解密.net中的mysql列

时间:2015-10-15 21:47:54

标签: mysql c#-4.0 encryption

我在mysql中有一个名为reference column的列,它是加密的。我有解密的钥匙。我正在使用entityframework重新获取数据,需要解密该列并将其推送到csv文件。有人可以使用c#

帮助我解密代码
public string DecryptStringFromBytes(string value)
{
    String encryptKey = "Youare@IsBe$t";
    byte[] key = Encoding.UTF8.GetBytes(encryptKey);
    byte[] cipherText = Encoding.UTF8.GetBytes(value);

    string plaintext = null;
    using (RijndaelManaged rijAlg = new RijndaelManaged())
    {
        rijAlg.GenerateIV();

        ICryptoTransform decryptor = rijAlg.CreateDecryptor(key, rijAlg.IV);

        using (MemoryStream msDecrypt = new MemoryStream(cipherText))
        {
            using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
            {
                using (StreamReader srDecrypt = new StreamReader(csDecrypt))
                {
                    plaintext = srDecrypt.ReadToEnd();
                }
            }
        }
    }
    return plaintext;
}

0 个答案:

没有答案