.NET下的加密编程

在.NET中可以加密所要使用的类全部都集中在system.security.cryptography它包含多种加密算法.

private sub Button1_click()

    Dim txt1 as Byte() '声明一个BYTE类型的变量。
    txt1=System.Text.AscIIEncoding.ASCII.GetBytes(TextBox1.Text) '读取输入文本,即要加密的文本。
    Dim key(16) as Byte
    key = System.Text.AscIIEncoding.ASCII.GetBytes(TextBox2.Text)'读取密码。
    Dim hma as new System.Security.cryptography.HMAcsHA1(key) '声明加密类,即使用何种加密方法。
    Dim csstream as new System.Security.cryptography.cryptostream(System.Io.stream.null,hma,security.cryptography.cryptostreammode.write) '进行加密转换。
    csstream.write(txt1,0,txt1.length)'将加密后的文本保存在TXT1这个变量中。
    csstream.close()
    TextBox3.text=System.Text.AscIIEnCoding.ASCII.GetString(hma.Hash)'显示加密文字。
End sub

posted on 2005-07-22 14:56  流星石  阅读(234)  评论(0编辑  收藏  举报