From: David T. <dav...@us...> - 2005-11-10 19:35:41
|
Update of /cvsroot/wonder/Wonder/Common/Frameworks/ERExtensions/Sources/er/extensions In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30958/Sources/er/extensions Modified Files: ERXCrypto.java Log Message: extracting base64 encoding and decoding into separate methods Index: ERXCrypto.java =================================================================== RCS file: /cvsroot/wonder/Wonder/Common/Frameworks/ERExtensions/Sources/er/extensions/ERXCrypto.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** ERXCrypto.java 10 Jun 2005 09:22:17 -0000 1.12 --- ERXCrypto.java 10 Nov 2005 19:35:33 -0000 1.13 *************** *** 387,392 **** stringBytes = ERXCompressionUtilities.deflateByteArray(stringBytes); byte[] raw = cipher.doFinal(stringBytes); ! sun.misc.BASE64Encoder enc = new sun.misc.BASE64Encoder(); ! encBase64String = enc.encode(raw); } catch(java.security.NoSuchAlgorithmException ex) { throw new NSForwardException(ex, "Couldn't find the DES algorithm; perhaps you do not have the SunJCE security provider installed properly?"); --- 387,391 ---- stringBytes = ERXCompressionUtilities.deflateByteArray(stringBytes); byte[] raw = cipher.doFinal(stringBytes); ! encBase64String = base64Encode(raw); } catch(java.security.NoSuchAlgorithmException ex) { throw new NSForwardException(ex, "Couldn't find the DES algorithm; perhaps you do not have the SunJCE security provider installed properly?"); *************** *** 397,402 **** --- 396,417 ---- } + /** + * Base64 encodes the passed in byte[] + */ + public static String base64Encode(byte[] byteArray) { + sun.misc.BASE64Encoder enc = new sun.misc.BASE64Encoder(); + String base64String = enc.encode(byteArray); + return base64String; + } /** + * Base64 decodes the passed in String + */ + public static byte[] base64Decode(String s) throws IOException { + sun.misc.BASE64Decoder enc = new sun.misc.BASE64Decoder(); + byte[] raw = enc.decodeBuffer(s); + return raw; + } + /** * Base64 decodes and then DES decrypts the passed in string using the * secret key returned by <code>secretKey</code>. *************** *** 417,422 **** Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding"); cipher.init(Cipher.DECRYPT_MODE, secretDESKey()); ! sun.misc.BASE64Decoder enc = new sun.misc.BASE64Decoder(); ! byte[] raw = enc.decodeBuffer(v); byte[] stringBytes = cipher.doFinal(raw); stringBytes = ERXCompressionUtilities.inflateByteArray(stringBytes); --- 432,436 ---- Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding"); cipher.init(Cipher.DECRYPT_MODE, secretDESKey()); ! byte[] raw = base64Decode(v); byte[] stringBytes = cipher.doFinal(raw); stringBytes = ERXCompressionUtilities.inflateByteArray(stringBytes); |