i working on updating password encryption utility entirely homegrown 1 built around jasypt , bouncy castle. utility encrypts password; encrypted string patched properties file , read in , decrypted grails application.
i wrote java command-line utility encrypting password. relevant java code is:
public class passwordutility { private final string salt = "randomstring"; private final standardpbestringencryptor encryptor = new standardpbestringencryptor(); public passwordutility( string seed ) { string password = salt + seed; encryptor.setprovider( new bouncycastleprovider() ); encryptor.setalgorithm( "pbewithsha256and192bitaes-cbc-bc" ); encryptor.setpassword( password ); } public string decrypt( string encryptedtext ) { string processtext = encryptedtext; return encryptor.decrypt( processtext ); } public string encrypt( string plaintext ) { return encryptor.encrypt( plaintext ); } }
the groovy code is:
class stringencryptor { string salt = "randomstring" private standardpbestringencryptor initcrypto( string keysplit ) { standardpbestringencryptor pbe = new standardpbestringencryptor() pbe.setprovider( new bouncycastleprovider() ) pbe.setalgorithm( "pbewithsha256and192bitaes-cbc-bc" ) string cryptkey = salt + keysplit pbe.setpassword( cryptkey ) return pbe } string encrypt( string keysplit, string encrypttext ) { standardpbestringencryptor pbe = initcrypto( keysplit ) pbe.encrypt( encrypttext ) } string decrypt( string keysplit, string encrypttext ) { log.info encrypttext log.info keysplit standardpbestringencryptor pbe = initcrypto( keysplit ) pbe.decrypt( encrypttext ) } }
when run passwordutility locally (on mac), paste results properties file , run grails locally, password decrypted correctly. when run passwordutility on rhel virtual server , paste results properties file, encryptionoperationnotpossibleexception, , looking @ code, implies decryption might have failed -- standardpbebyteencryptor line 1055). when take string mac , try decrypt on rhel, decryption returns null. able take string 1 rhel box , decrypt on rhel box.
the issue there wildcard characters in password coming in. when changed part of password alphanumeric characters (or alphanumeric characters , dash) crypto working cross-platform.
Comments
Post a Comment