ICryptoTransform.TransformFinalBlock与ICryptoTransform.TransformBlock [英] ICryptoTransform.TransformFinalBlock vs ICryptoTransform.TransformBlock

查看:143
本文介绍了ICryptoTransform.TransformFinalBlock与ICryptoTransform.TransformBlock的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习.net中的密码学,为什么方法1起作用而2引发了参数异常。
有关完整代码,请参见对称算法异常

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.TransformFinalBlock

1- ICryptoTransform.TransformFinalBlock

2- ICryptoTransform.TransformBlock

2- ICryptoTransform.TransformBlock

谢谢

推荐答案

您应该使用 CryptoStream ,它将自动调用正确的 ICryptoTransform 方法。

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

例如:

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();

这篇关于ICryptoTransform.TransformFinalBlock与ICryptoTransform.TransformBlock的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆