您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Rijndael在Java中的支持

Rijndael在Java中的支持

Java开箱即用地包含AES。Rijndael是AES。您不需要任何外部库。您只需要这样的东西:

byte[] sessionKey = null; //Where you get this from is beyond the scope of this post
byte[] iv = null ; //Ditto
byte[] plaintext = null; //Whatever you want to encrypt/decrypt
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
//You can use ENCRYPT_MODE or DECRYPT_MODE
cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(sessionKey, "AES"), new IvParameterSpec(iv));
byte[] ciphertext = cipher.doFinal(plaintext);

就是这样,用于加密/解密。如果要处理大量数据,则最好读取16字节倍数的块,然后调用update而不是doFinal(您只需在最后一个块上调用doFinal)。

java 2022/1/1 18:14:23 有497人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶