如何将此Rijndael C#代码转换为Java?

时间:2019-07-18 04:33:02

标签: java c# rijndael

我想将C#代码中的Rijndael加密值解密为Java。

我该怎么办?帮助。

public string Encrypt(string Plain, string password) {
    RijndaelManaged RijndaelCipher = new RijndaelManaged();
    byte[] PlainBytes = System.Text.Encoding.Unicode.GetBytes(Plain);
    byte[] Salt = new byte[] {0x02, 0x76, 0x06, 0x6e, 0x99, 0x4d, 0x65, 0x41, 0x76, 0x69, 0x64, 0x24, 0x61};

    PasswordDeriveBytes SecureKey = new PasswordDeriveBytes(Password, Salt);

    ICryptoTransform Encryptor = RijndaelCipher.CreateEncryptor(SecureKey.GetBytes(32), SecureKey.GetBytes(16));

    MemoryStream memoryStream = new MemoryStream();
    CryptoStream cryptoStream = new CryptoStream(memoryStream, Encryptor, CryptoStreamMode.Write);

    cryptoStream.Write(PlainBytes, 0, PlainBytes.Length);
    cryptoStream.FlushFinalBlock();
    byte[] CipherBytes = memoryStream.ToArray();

    return Convert.ToBase64String(CipherBytes);
}

0 个答案:

没有答案