小编att*_*tta的帖子

使用AES和CFB模式

你能否告诉我如何在CFB模式下使用AES(这样输入(纯文本)和输出(加密文本)的大小保持不变.我已经尝试用AES/CFB/NoPadding替换AES,但它不起作用.应用程序崩溃.我使用以下代码.请帮助我使用CFB的AES工作.谢谢

公共类SimpleCrypto {

public static String encrypt(String seed, String cleartext) throws Exception {
    byte[] rawKey = getRawKey(seed.getBytes());
    byte[] result = encrypt(rawKey, cleartext.getBytes());
    return toHex(result);
}

public static String decrypt(String seed, String encrypted) throws Exception {
    byte[] rawKey = getRawKey(seed.getBytes());
    byte[] enc = toByte(encrypted);
    byte[] result = decrypt(rawKey, enc);
    return new String(result);
}


private static byte[] getRawKey(byte[] seed) throws Exception {
    KeyGenerator kgen = KeyGenerator.getInstance("AES");
    SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");
    sr.setSeed(seed);
    kgen.init(128, sr); // 192 and 256 bits may not be available …
Run Code Online (Sandbox Code Playgroud)

java android aes

6
推荐指数
1
解决办法
6923
查看次数

标签 统计

aes ×1

android ×1

java ×1