PointyCastle / pointycastle

Moved into the Bouncy Castle project: https://github.com/bcgit/pc-dart
MIT License
270 stars 76 forks source link

AES Encrypt、Decrypt #142

Open pyp163 opened 6 years ago

pyp163 commented 6 years ago

public static String aesEncrypt(String data, String key) { try {

       String spec = key.substring(0, 16);
        SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes(), "AES");
        Cipher cipher = Cipher.getInstance("AES/CFB/NoPadding");
        IvParameterSpec iv = new IvParameterSpec(spec.getBytes());
        cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv);
        byte[] bytes = cipher.doFinal(data.getBytes("UTF-8"));
        return new String(Base64.encode(bytes));
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

}

有没有能解决这样的加解密的例子? Are there any examples of encryption and decryption that can be solved? 我找了很久都没有找一个能解决问题的例子 I've been looking for a long time without finding an example to solve the problem

stevenroose commented 5 years ago

Please take a look at this example and let me know if it works for you: https://github.com/PointyCastle/pointycastle/pull/111