Skip to main content
better title; removed fluff
Source Link
Artjom B.
  • 62k
  • 26
  • 137
  • 236

AES Encript Encrypt and Decriptdecrypt with ApacheAES and Base64 encoding

I have following programmeprogram for encrypts aencrypting data.

And as the exception says "how to decrypting without padded cipher?"

Thank You.

AES Encript and Decript with Apache Base64

I have following programme for encrypts a data.

And as the exception says "how to decrypting without padded cipher?"

Thank You.

Encrypt and decrypt with AES and Base64 encoding

I have following program for encrypting data.

And as the exception says "how to decrypting without padded cipher?"

Pending tag syncronymization: http://meta.stackoverflow.com/questions/275672/lets-synonymize-a-few-plural-unnecessary-tags?cb=1
Link

AES Encript and Decript problem with Apache Base64

edited body
Source Link
Harshana
  • 7.7k
  • 35
  • 116
  • 183
import java.security.Key; import javax.crypto.Cipher; import javax.crypto.spec.SecretKeySpec; import org.apache.commons.codec.binary.Base64; public class Test { private static final String ALGORITHM = "AES"; private static final byte[] keyValue = "ADBSJHJS12547896".getBytes(); public static void main(String args[]) throws Exception { String encriptValue = encrypt("dias7""dude5"); decrypt(encriptValue); } /** * @param args * @throws Exception */ public static String encrypt(String valueToEnc) throws Exception { Key key = generateKey(); Cipher c = Cipher.getInstance(ALGORITHM); c.init(Cipher.ENCRYPT_MODE, key); System.out.println("valueToEnc.getBytes().length "+valueToEnc.getBytes().length); byte[] encValue = c.doFinal(valueToEnc.getBytes()); System.out.println("encValue length" + encValue.length); byte[] encryptedByteValue = new Base64().encode(encValue); String encryptedValue = encryptedByteValue.toString(); System.out.println("encryptedValue " + encryptedValue); return encryptedValue; } public static String decrypt(String encryptedValue) throws Exception { Key key = generateKey(); Cipher c = Cipher.getInstance(ALGORITHM); c.init(Cipher.DECRYPT_MODE, key); byte[] enctVal = c.doFinal(encryptedValue.getBytes()); System.out.println("enctVal length " + enctVal.length); byte[] decordedValue = new Base64().decode(enctVal); return decordedValue.toString(); } private static Key generateKey() throws Exception { Key key = new SecretKeySpec(keyValue, ALGORITHM); return key; } } 
import java.security.Key; import javax.crypto.Cipher; import javax.crypto.spec.SecretKeySpec; import org.apache.commons.codec.binary.Base64; public class Test { private static final String ALGORITHM = "AES"; private static final byte[] keyValue = "ADBSJHJS12547896".getBytes(); public static void main(String args[]) throws Exception { String encriptValue = encrypt("dias7"); decrypt(encriptValue); } /** * @param args * @throws Exception */ public static String encrypt(String valueToEnc) throws Exception { Key key = generateKey(); Cipher c = Cipher.getInstance(ALGORITHM); c.init(Cipher.ENCRYPT_MODE, key); System.out.println("valueToEnc.getBytes().length "+valueToEnc.getBytes().length); byte[] encValue = c.doFinal(valueToEnc.getBytes()); System.out.println("encValue length" + encValue.length); byte[] encryptedByteValue = new Base64().encode(encValue); String encryptedValue = encryptedByteValue.toString(); System.out.println("encryptedValue " + encryptedValue); return encryptedValue; } public static String decrypt(String encryptedValue) throws Exception { Key key = generateKey(); Cipher c = Cipher.getInstance(ALGORITHM); c.init(Cipher.DECRYPT_MODE, key); byte[] enctVal = c.doFinal(encryptedValue.getBytes()); System.out.println("enctVal length " + enctVal.length); byte[] decordedValue = new Base64().decode(enctVal); return decordedValue.toString(); } private static Key generateKey() throws Exception { Key key = new SecretKeySpec(keyValue, ALGORITHM); return key; } } 
import java.security.Key; import javax.crypto.Cipher; import javax.crypto.spec.SecretKeySpec; import org.apache.commons.codec.binary.Base64; public class Test { private static final String ALGORITHM = "AES"; private static final byte[] keyValue = "ADBSJHJS12547896".getBytes(); public static void main(String args[]) throws Exception { String encriptValue = encrypt("dude5"); decrypt(encriptValue); } /** * @param args * @throws Exception */ public static String encrypt(String valueToEnc) throws Exception { Key key = generateKey(); Cipher c = Cipher.getInstance(ALGORITHM); c.init(Cipher.ENCRYPT_MODE, key); System.out.println("valueToEnc.getBytes().length "+valueToEnc.getBytes().length); byte[] encValue = c.doFinal(valueToEnc.getBytes()); System.out.println("encValue length" + encValue.length); byte[] encryptedByteValue = new Base64().encode(encValue); String encryptedValue = encryptedByteValue.toString(); System.out.println("encryptedValue " + encryptedValue); return encryptedValue; } public static String decrypt(String encryptedValue) throws Exception { Key key = generateKey(); Cipher c = Cipher.getInstance(ALGORITHM); c.init(Cipher.DECRYPT_MODE, key); byte[] enctVal = c.doFinal(encryptedValue.getBytes()); System.out.println("enctVal length " + enctVal.length); byte[] decordedValue = new Base64().decode(enctVal); return decordedValue.toString(); } private static Key generateKey() throws Exception { Key key = new SecretKeySpec(keyValue, ALGORITHM); return key; } } 
deleted 11 characters in body; added 76 characters in body
Source Link
Harshana
  • 7.7k
  • 35
  • 116
  • 183
Loading
Source Link
Harshana
  • 7.7k
  • 35
  • 116
  • 183
Loading