ICryptoTransform.TransformFinalBlock vs ICryptoTransform.TransformBlock

前端 未结 1 560
情歌与酒
情歌与酒 2021-01-17 20:09

I am Learning cryptography in .net, why method 1 works while 2 fired argument exception. See Symmetric Algorithm exception for a complete code

1- ICryptoTransform.Tr

1条回答
  •  余生分开走
    2021-01-17 20:35

    You should be using a CryptoStream, which will automatically call the correct ICryptoTransform methods.

    For example:

    var stream = new MemoryStream();
    using (var transform = symAlgo.CreateEncryptor())
    using (var cryptoStream = new CryptoStream(stream, transform, CryptoStreamMode.Write))
    using (var writer = new StreamWriter(cryptoStream))
        writer.Write(someString);
    
    byte[] cipherBytes = stream.ToArray();
    

    0 讨论(0)
提交回复
热议问题