在以下加密代码中做了什么? [英] What is done in the following code of encryption?

查看:75
本文介绍了在以下加密代码中做了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 私有 功能加密(clearText 作为 字符串作为 字符串 
Dim EncryptionKey As 字符串 = MAKV2SPBNI99212
Dim clearBytes As Byte ()= Encoding.Unicode.GetBytes(clearText)
使用加密器作为 Aes = Aes.Create()
Dim pdb 作为 Rfc2898DeriveBytes(EncryptionKey, 字节(){& H49,& H76,& H61,& H6E,& H20,& H4D,_
& H65,& H64,& H76,& H65,& H64,& H65,_
& H76})
encryptor.Key = pdb.GetBytes( 32
encryptor.IV = pdb.GetBytes( 16
使用 ms 作为 MemoryStream()
< span class =code-keyword>使用 cs 作为 CryptoStream(ms,加密器.CreateEncryptor(),CryptoStreamMode.Write)
cs.Write(clearBytes, 0 ,clearBytes.Length)
cs.Close()
结束 使用
clearText = Convert.ToBase64String(ms.ToArray())
结束 使用
结束 使用
返回 clearText
结束 功能





[edit]已添加代码块 - OriginalGriff [/ edit]

解决方案

相当多,有两种方法可以解释所做的事情: br />
1)它加密数据



2)逐行解释代码,因为它对于初学者来说非常复杂。 />


您是否知道逐行解释代码的工作量是多少?

每一行都需要一段解释!例如:

 int next = r.Next(); 



创建一个名为next的新变量,它可以包含一个整数值。从先前声明的Random实例r,调用Next方法获取一个新的随机数,并将其分配给next变量。



可以你想象我们需要多长时间才能解释一个像你的例子一样的非常短的代码片段,一行一行?



如果你有特定的问题,那么问一个关于它的问题。但首先考虑一下 - 您是否想坐下45分钟并且无缘无故地输入逐行描述?



所以,你要么需要找一本关于加密的书,或者首先使用谷歌和MSDN来了解每个类和方法的用途,它是如何做到的,以及它是如何使用的。

但是没人(除了可能的代码的作者)将以你想要的深度向你解释。


我认为这篇文章似乎起源的确切代码解释了它:



http://aspsnippets.com/Articles/AES-Encryption-Decryption-Cryptography-Tutorial-with-example-in-ASPNet-using-C-and-VBNet.aspx

Private Function Encrypt(clearText As String) As String
        Dim EncryptionKey As String = "MAKV2SPBNI99212"
        Dim clearBytes As Byte() = Encoding.Unicode.GetBytes(clearText)
        Using encryptor As Aes = Aes.Create()
            Dim pdb As New Rfc2898DeriveBytes(EncryptionKey, New Byte() {&H49, &H76, &H61, &H6E, &H20, &H4D, _
             &H65, &H64, &H76, &H65, &H64, &H65, _
             &H76})
            encryptor.Key = pdb.GetBytes(32)
            encryptor.IV = pdb.GetBytes(16)
            Using ms As New MemoryStream()
                Using cs As New CryptoStream(ms, encryptor.CreateEncryptor(), CryptoStreamMode.Write)
                    cs.Write(clearBytes, 0, clearBytes.Length)
                    cs.Close()
                End Using
                clearText = Convert.ToBase64String(ms.ToArray())
            End Using
        End Using
        Return clearText
    End Function



[edit]Code block added - OriginalGriff[/edit]

解决方案

Pretty much, there are two ways to explain what is done:
1) "It encrypts data"
Or
2) Explain the code line by line, because it's quite involved for a beginner.

Do you have any idea how much work explaining code line by line is?
Every single line needs a paragraph of explanation! For example:

int next = r.Next();


Create a new variable called "next" which can hold a integer value. From the previously declared Random instance "r", call the "Next" method to get a new random number, and assign it to the "next" variable.

Can you imagine how long it would take us to explain even a very short code fragment like your example, line by line?

If you have a specific problem, then ask a question about it. But think first - would you want to sit down for 45 minutes and type up a line-by-line description for no good reason?

So, you either need to find a book on encryption, or start by using Google and MSDN to follow what each of the classes and methods used does, how it does it, and how it is used.
But nobody (except possibly the author of the code) is going to explain that to you in the depth you want.


I think this article, where the exact code seems to have originated, explains it:

http://aspsnippets.com/Articles/AES-Encryption-Decryption-Cryptography-Tutorial-with-example-in-ASPNet-using-C-and-VBNet.aspx


这篇关于在以下加密代码中做了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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