这个加密代码在android中出了什么问题?

时间:2011-02-10 11:06:02

标签: android encryption

  

可能重复:
  what's wrong with this encryption code in android?

public String Encryption(String toEncrypt) throws Exception
{
        Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
        EditText et = (EditText) findViewById(R.id.entry);
        byte[] input = toEncrypt.getBytes();
        byte[] keyBytes = "hello".getBytes();

        //et.setText("in encryption");
        SecretKeySpec key = new SecretKeySpec(keyBytes, "AES");
        Cipher cipher = Cipher.getInstance("AES/ECB/PKCS7Padding", "BC");

        //et.setText("in encryption");
        cipher.init(Cipher.ENCRYPT_MODE, key);
        et.setText("in encryption");
        byte[] cipherText = new byte[cipher.getOutputSize(input.length)];
        int ctLength = cipher.update(input, 0, input.length, cipherText, 0);
        ctLength += cipher.doFinal(cipherText, ctLength);
        //et.setText("in encryption");
        //return "abc";
        return cipherText.toString();
}

(cipher.init(Cipher.ENCRYPT_MODE, key);)行似乎有某种错误。

有人可以告诉我这行代码有什么问题吗?

0 个答案:

没有答案