Reading from a cryptostream to the end of the stream

前端 未结 3 1308
难免孤独
难免孤独 2020-12-17 04:30

I\'m having some trouble with the code below. I have a file in a temporary location which is in need of encryption, this function encrypts that data which is then stored at

3条回答
  •  佛祖请我去吃肉
    2020-12-17 04:42

    The KeySize must be specified first. This looks like a bug e.g. this works

                using (var aes = new AesManaged())
                {
                    aes.KeySize = 256;
                    aes.Mode = CipherMode.CBC;
                    aes.IV = iv;
                    aes.Key = passwordHash;
                    aes.Padding = PaddingMode.PKCS7;
    

    but this doesn't

                using (var aes = new AesManaged())
                {
                    aes.Mode = CipherMode.CBC;
                    aes.IV = iv;
                    aes.Key = passwordHash;
                    aes.Padding = PaddingMode.PKCS7;
                    aes.KeySize = 256;
    

提交回复
热议问题