(九) shiro採用AES加密和解密
阿新 • • 發佈:2018-12-25
1 程式碼
AesEncoding.java
2 結果package nufront.shiro.util; import java.security.Key; import org.apache.shiro.codec.Hex; import org.apache.shiro.crypto.AesCipherService; public class AesEncoding { /** * @param args */ public static void main(String[] args) { AesCipherService aesCipherService = new AesCipherService(); aesCipherService.setKeySize(128); //設定key長度 //生成key Key key = aesCipherService.generateNewKey(); System.out.println("key = " + key); String text = "AesEncoding"; //加密 String encrptText = aesCipherService.encrypt(text.getBytes(), key.getEncoded()).toHex(); //解密 String text2 = new String(aesCipherService.decrypt(Hex.decode(encrptText), key.getEncoded()).getBytes()); System.out.println("原始值 : " + text); System.out.println("加密值 : " + encrptText); System.out.println("解密值 : " + text2); } }
key = [email protected]
原始值 : AesEncoding
加密值 : d4bbd7b1c184e09996e80e443a5e05c6c9cfc1257d4762105ad08341d32e5ea5
解密值 : AesEncoding