在我的项目中,我正在使用一种许可方法,在用户输入许可密钥后,他的产品将被激活。我使用以下代码,但我收到一个异常,提示“填充无效且无法删除”。以下是我的代码
public void ValidateProductKey()
{
RSACryptoServiceProvider _cryptoService = new RSACryptoServiceProvider();
string productKey = "G7MA4Z5VR5R3LG001AS1N5HA3YHX05";
byte[] keyBytes = Base32Converter.FromBase32String(productKey); //Base32Converter is my customized method which returns byte of values;
byte[] signBytes = new byte[2];
byte[] hiddenBytes = new byte[16];
using (MemoryStream stream = new MemoryStream(keyBytes))
{
stream.Read(hiddenBytes, 0, 8);
stream.Read(signBytes, 0, 2);
stream.Read(hiddenBytes, 8, hiddenBytes.Length - 8);
keyBytes = stream.ToArray();
}
byte[] sign = _cryptoService.SignData(signBytes, new SHA1CryptoServiceProvider());
byte[] rkey = new byte[32];
byte[] rjiv = new byte[16];
Array.Copy(sign, rkey, 32);
Array.Copy(sign, 32, rjiv, 0, 16);
SymmetricAlgorithm algorithm = new RijndaelManaged();
try
{
hiddenData = algorithm.CreateDecryptor(rkey, rjiv).TransformFinalBlock(hiddenBytes,0,hiddenBytes.Length);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
当到达“hiddenData”变量时,我得到一个异常,因为“填充无效并且无法删除”。任何帮助将非常感激。