2014-06-10 3 views
0

AES를 사용하여 암호화하려고합니다.AES 암호화 던집 "잘못된 키 크기 오류"

다음
private final static String ENCRYPTION_ALGORITHM = "AES"; 
private final static String CIPHER_TRANSFORMATION = "AES/CBC/PKCS5Padding"; 
private final static String ENCODING = "UTF-8"; 
private final static String KEY_STRING = "C0BAE23DF8B51807B3E17D21925FADF273A70181E1D81B8EDE6C76A5C1F1716E"; 

public static String encryptData(String plainText) { 

    String keyString = KEY_STRING; 
    String encryptedValue = null; 

    byte[] keyValue = DatatypeConverter.parseHexBinary(keyString); 
    Key key = new SecretKeySpec(keyValue, ENCRYPTION_ALGORITHM); 
    Cipher cipher; 
    byte[] encVal; 

    try { 
     cipher = Cipher.getInstance(CIPHER_TRANSFORMATION); 
     cipher.init(Cipher.ENCRYPT_MODE, key, new IvParameterSpec(new byte[64])); 
     encVal = cipher.doFinal(plainText.getBytes()); 
     encryptedValue = (new BASE64Encoder()).encode(encVal); 
    } catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | IllegalBlockSizeException | BadPaddingException | InvalidAlgorithmParameterException e) { 
     System.out.println("Error in EncryptData.encryptData(): " + e.getMessage()); 
     encryptedValue = null; 
    } 


    return encryptedValue; 
} 

오류입니다, 이클립스에서 실행하는 동안 내가 갖는 :

Error in EncryptData.encryptData(): Illegal key size 

어떤 제안이나 내가 잘못 뭐하는 거지 다음은 내 코드입니다?

답변