【问题标题】:stream cypher encryption in AESAES 中的流密码加密
【发布时间】:2017-03-08 09:00:26
【问题描述】:

我在 C# 中实现 AES 256 位算法,但我正在加密需要填充的 128 位纯文本块,所以我不想填充并想使用流密码

  1. 使用流密码而不是使用 128 位块
  2. 逐字节加密流

    CryptLib _crypt = new CryptLib();
    
    //string plainText = "This is the text to be encrypted";
    String iv = CryptLib.GenerateRandomIV(16); //16 bytes = 128 bits
    string key = CryptLib.getHashSha256("my secret key", 31); //32 bytes = 256 bits
    MessageBox.Show(arm);//////////////////////
    String cypherText = _crypt.encrypt(string1, key, iv);
    Console.WriteLine("iv=" + iv);
    Console.WriteLine("key=" + key);
    Console.WriteLine("Cypher text=" + cypherText);
    MessageBox.Show(cypherText);
    textBox1.Text = cypherText;
    Console.WriteLine("Plain text =" + _crypt.decrypt(cypherText, key, iv));
    MessageBox.Show(_crypt.decrypt(cypherText, key, iv));
    
    
    
    String dypher = _crypt.decrypt(cypherText, key, iv);
    string outp = string.Empty;
    char[] value = dypher.ToCharArray();
    

【问题讨论】:

  • 你有什么问题?
  • 我的问题不是加密需要填充的 128 位块,我可以像流密码一样逐字节加密,因为我不想使用块,因为它需要填充我希望你现在理解我的问题
  • 我前段时间创建了 AES-CTR 的 C# 实现,它是 AES 的流加密模式。见stackoverflow.com/a/29562965/613130

标签: c# encryption aes cryptlib


【解决方案1】:

如果输入数据总是是块大小的精确倍数,您可以不指定填充。

如果您有未知非统一块长度的数据,则填充是处理该问题的一般方法。 为什么你不想使用填充。

另外:

通常在加密数据前加上 IV 以在解密期间使用。 IV 不需要保密,通过这种方法,IV 不需要以其他方式共享,并且可以很容易地成为每次加密的不同随机值。

使用哈希函数从密码(字符串)派生密钥不被认为是安全的,而是使用密钥派生函数,例如 PBKDF2

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-21
    • 1970-01-01
    • 2021-06-21
    • 2011-01-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多