问题描述
我正在尝试找出同事写的一些代码,但是 TransformFinalBlock 的文档并没有真正解释任何内容.它说它转换指定字节数组的指定区域"并返回计算的转换",但是没有解释执行哪种转换.这是我的同事写的代码:
I am trying to figure out some code a coworker wrote, but the documentation for TransformFinalBlock does not really explain anything. It says it "transforms the specified region of the specified byte array" and returns "the computed transform", but it doesn''t explain what kind of transform is performed. Here is the code my coworker wrote:
Public Shared Function Encrypt(ByVal str As String, ByVal strKey As String) As String
cryptDES3.Key = cryptMD5Hash.ComputeHash(ASCIIEncoding.ASCII.GetBytes(strKey))
cryptDES3.Mode = CipherMode.ECB
Dim desdencrypt As ICryptoTransform = cryptDES3.CreateEncryptor()
Dim buff() As Byte = ASCIIEncoding.ASCII.GetBytes(str)
Return (Convert.ToBase64String(desdencrypt.TransformFinalBlock(buff, 0, buff.Length)))
End Function
我认为这不是执行加密的正确方法(我使用的是利用 CryptoStream
的技术),但是我不确定以上代码不正确. Mabye这只是在无论如何使用字节数组时避免流的一种聪明方法.没有把握.我想自己可以节省几个小时,以防万一你们比我更了解加密.
I''m thinking this is not the correct way to perform encryption (I''m using a technique that makes use of CryptoStream
), but I can''t be sure the above code is incorrect. Mabye this is just a clever way to avoid a stream when you''re working with byte arrays anyway. Not sure. I thought I''d save myself a few hours in case any of you know more about encryption than I do.
推荐答案
这篇关于ICryptoTransform.TransformFinalBlock实际做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!