我没有投反对票,但是您的问题(例如来源)没有太多可以解释的地方。但是,我刚刚使用此代码进行了加密:
public string SagePayEncryptAndEncode(string inputText, string key)
{
using (var AES = new RijndaelManaged())
{
// Set the mode, padding and block size for the key
AES.Padding = PaddingMode.PKCS7;
AES.Mode = CipherMode.CBC;
AES.KeySize = 128;
AES.BlockSize = 128;
// Convert key and input text into byte arrays
Byte[] keyAndIvBytes = UTF8Encoding.UTF8.GetBytes(key);
Byte[] inputBytes = UTF8Encoding.UTF8.GetBytes(inputText);
// Create streams and encryptor object
using (var memoryStream = new MemoryStream())
using (var cryptoStream = new CryptoStream(memoryStream, AES.CreateEncryptor(keyAndIvBytes, keyAndIvBytes), CryptoStreamMode.Write))
{
// Perform encryption
cryptoStream.Write(inputBytes, 0, inputBytes.Length);
cryptoStream.FlushFinalBlock();
// Get encrypted stream into byte array
var outBytes = memoryStream.ToArray();
// Manually close streams
memoryStream.Close();
cryptoStream.Close();
AES.Clear();
//return Convert.ToBase64String(outBytes);
return BitConverter.ToString(outBytes).Replace("-", String.Empty);
}
}
}
然后,您需要将结果值存储在隐藏的“Crypt”字段中并在前面加上“@”。
<input name='Crypt' type='hidden' value='@<InsertResultHere>' />
需要注意的一点是,它似乎只能使用十六进制编码,而不是文档所暗示的 Base64 编码。
希望这可以帮助!