我有信用卡号进行加密并存储在数据库作为一个字符串。 我做了以下
RijndaelManaged rijMan = new RijndaelManaged();
byte[] encrypt = Encrypt(txtCredit.Text, rijMan.Key, rijMan.IV);
string card = Convert.ToBase64String(encrypt);
string key = Convert.ToBase64String(rijMan.Key);
string iv = Convert.ToBase64String(rijMan.IV);
这是加密功能:
public static byte[] Encrypt(string message, byte[] key, byte[] iv)
{
byte[] encrypted;
using (RijndaelManaged rijMan = new RijndaelManaged())
{
rijMan.Key = key;
rijMan.IV = iv;
ICryptoTransform encrypt = rijMan.CreateEncryptor(rijMan.Key, rijMan.IV);
using (MemoryStream ms = new MemoryStream())
{
using (CryptoStream cs = new CryptoStream(ms, encrypt, CryptoStreamMode.Write))
{
using (StreamWriter sw = new StreamWriter(cs))
{
sw.Write(message);
}
encrypted = ms.ToArray();
}
}
}
return encrypted;
}
我和他们都存储在数据库中。 这似乎是罚款。 但是,当我回检索数据库,从串并使用System.Text.Encoding.UTF8.GetBytes(string)
转换为byte
,它抛出一个异常
指定的初始化向量(IV)不适用于本算法的块大小匹配。
是否有可能产生IV这样的,这是16个字节? 在此先感谢您的答复