Login
...or Sign up
Home
Search
Search Code Snippets
Search People
Crypt and Decrypt with Java
public static String decrypt3DES(String code, SecretKey key) throws NoSuchAlgorithmException, InvalidKeyException, IOException, IllegalBlockSizeException, NoSuchPaddingException, BadPaddingException { Cipher cipher = Cipher.getInstance("DESede"); cipher.init(Cipher.DECRYPT_MODE, key); BASE64Decoder decoder = new BASE64Decoder(); byte[] raw = decoder.decodeBuffer(code); byte[] stringBytes = cipher.doFinal(raw); String result = new String(stringBytes,"UTF8"); return result; } public static String encrypt3DES(String code, SecretKey key) throws NoSuchAlgorithmException, InvalidKeyException, NoSuchPaddingException, IOException, IllegalStateException, IllegalBlockSizeException, BadPaddingException { Cipher cipher = Cipher.getInstance("DESede"); cipher.init(Cipher.ENCRYPT_MODE,key); byte[] stringBytes=code.getBytes("UTF8"); byte[] raw=cipher.doFinal(stringBytes); BASE64Encoder encoder = new BASE64Encoder(); String base64 = encoder.encode(raw); return base64; }
Score: 0/10
Would you like to comment?
Sign up
for a free account or
sign in
(if you are already a member).
URL:
Embed:
Uploaded on 3/21/2008 8:26:44 AM
by
cara
Programming Language:
java
Tags:
crypt
decrypt
java
Viewed 1314 times
Help
Help by email
What is Naslu?
|
About Naslu
|
Contact
|
Terms of Use
|
Downloads
|
Webprogramacion.com
|
Blog
|
Top
Links
Select language:
Español
|
English
© 2009 naslu.com