java 代码如下:
public static String AesEncrypt(String seed, String cleartext) throws Exception { KeyGenerator kgen = KeyGenerator.getInstance("AES"); SecureRandom random = SecureRandom.getInstance("SHA1PRNG"); random.setSeed(seed.getBytes()); kgen.init(128, random); // 192 and 256 bits may not be available SecretKey skey = kgen.generateKey();
byte[] rawKey = skey.getEncoded(); SecretKeySpec skeySpec = new SecretKeySpec(rawKey, "AES"); Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.ENCRYPT_MODE, skeySpec); byte[] byte_encode=cleartext.getBytes("utf-8") byte[] encrypted = cipher.doFinal(byte_encode); string AES_encode=new String(new BASE64Encoder().encode(encrypted)); return AES_encode;}
求翻译
添加回答
举报
0/150
提交
取消