TripleDES键 - 生成字符串键

时间:2016-07-20 20:05:26

标签: c# security encryption 3des tripledes

我收到了TripleDES密钥,如下所示:

每个16字节HEX字符串的2个组件。

组件1 :00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

KCV 1 :0000000000000000

组件2 :00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

KCV 2 :0000000000000000

我需要将最终密钥作为UTF8字符串存储在web.config(开发阶段)中,有一个实现在生产中使用这种方法运行,密钥长度为24个字符,我只检索web.config中的密钥为遵循:

Encoding.UTF8.GetBytes(secreteKeyValue);
//Secret key from web.config

如何从这些组件生成最终密钥,将UTF 8字符串存储在web.config中并在下面的方法中使用?

public static byte[] TripleDes(byte[] inputBuffer, byte[] key)
    {
        using (TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider())
        {
            des.Key = key;
            des.Mode = CipherMode.ECB;
            des.Padding = PaddingMode.None;

            byte[] result;

            using (MemoryStream stream = new MemoryStream())
            using (CryptoStream cryptoStream = new CryptoStream(stream, des.CreateEncryptor(), CryptoStreamMode.Write))
            {
                cryptoStream.Write(inputBuffer, 0, inputBuffer.Length);
                cryptoStream.Flush();
                result = stream.ToArray();
            }

            return result;
        }
    }

0 个答案:

没有答案