2013-01-04 4 views
0

의 해독은 암호화와 안드로이드에서 텍스트를 해독하는 것이 가능하지만 난이 오류를 발견하지만 난 그것을 해결하는 방법을 잘 모릅니다암호화, 텍스트

코드는 ...

Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());   
    byte[] input = " www.java2s.com ".getBytes(); 
    byte[] keyBytes = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
     0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 }; 

    SecretKeySpec key = new SecretKeySpec(keyBytes, "AES"); 
    Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding", "BC"); 
    System.out.println("input text : " + new String(input)); 

    // encryption pass 

    byte[] cipherText = new byte[input.length]; 
    cipher.init(Cipher.ENCRYPT_MODE, key); 
    int ctLength = cipher.update(input, 0, input.length, cipherText, 0); 
    ctLength += cipher.doFinal(cipherText, ctLength); 
    System.out.println("cipher text: " + new String(cipherText) + " bytes: " + ctLength); 

    // decryption pass 

    byte[] plainText = new byte[ctLength]; 
    cipher.init(Cipher.DECRYPT_MODE, key); 
    int ptLength = cipher.update(cipherText, 0, ctLength, plainText, 0); 
    ptLength += cipher.doFinal(plainText, ptLength); 
    System.out.println("plain text : " + new String(plainText) + " bytes: " + ptLength); 

오류를 표시하는 첫 번째 줄

+2

무엇이 오류입니까? –

+1

ECB가 안전하지 않습니다. – SLaks

+0

에서 http://www.androidsnippets.com/encryptdecrypt-strings을보세요. – itsrajesh4uguys

답변

0

키를 수정하거나 비보안 암호를 생성 할 때 암호화가 매우 취약해진다는 사실을 먼저 알아야합니다!

See my answer here 당신에게 유용한 암호 기반 AES 암호화/암호 해독을 수행하는 SecurityUtil 클래스를 쉽게 찾을 수 있습니다.

관련 문제