AES与CFB模式

时间:2014-04-15 09:43:32

标签: android encryption

我想用Base64和crypt(带CFB模式的AES)对我的Url-params进行编码,但它不起作用,我无法得到错误。有人能帮我吗?这是我的代码:

    private String toBase64Crypt(String cryptString) {
    try {
        SecretKeySpec key = new SecretKeySpec(pwd.getBytes("UTF8"), "AES");

        byte[] cryptByte = cryptString.getBytes("UTF8"); 

        Cipher cipher = Cipher.getInstance("AES");
        cipher.init(Cipher.ENCRYPT_MODE, key);
        cryptString = Base64.encodeToString(cipher.doFinal(cryptByte),Base64.DEFAULT);

    } catch (InvalidKeyException e) {
        e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (NoSuchPaddingException e) {
        e.printStackTrace();
    } catch (IllegalBlockSizeException e) {
        e.printStackTrace();
    } catch (BadPaddingException e) {
        e.printStackTrace();
    }

    return cryptString;
}

0 个答案:

没有答案