java AES 加密解密翻译为c#代码

2019-01-02 21:25发布

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;
}

 

求翻译

1条回答
登录 后发表回答