注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

樱之花

叶散的时候,你明白欢聚;花谢的时候,你明白青春.

 
 
 

日志

 
 
关于我

分类中“我的实验室”是我在日常工作中的一些知识总结,有些写的比较匆忙,可能大家在阅读时会产生困扰,后期有时间我会重新整理编辑,谢谢大家的到访,您们的支持是我前进的动力!

网易考拉推荐

DES加密解密  

2012-11-02 16:38:06|  分类: .NET/C# |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

代码:

Imports System.Security.cryptography

    Private mCSP As New DESCryptoServiceProvider

    Private Function EncryptString(ByVal Value As String) As String
        Try
            Dim ct As ICryptoTransform
            Dim ms As MemoryStream
            Dim cs As CryptoStream
            Dim byt() As Byte

            ct = mCSP.CreateEncryptor(mCSP.Key, mCSP.IV)

            byt = Encoding.UTF8.GetBytes(Value)

            ms = New MemoryStream
            cs = New CryptoStream(ms, ct, CryptoStreamMode.Write)
            cs.Write(byt, 0, byt.Length)
            cs.FlushFinalBlock()

            cs.Close()

            Return Convert.ToBase64String(ms.ToArray())
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

        Return Nothing
    End Function

    Private Function DecryptString(ByVal Value As String) As String
        Try
            Dim ct As ICryptoTransform
            Dim ms As MemoryStream
            Dim cs As CryptoStream
            Dim byt() As Byte

            ct = mCSP.CreateDecryptor(mCSP.Key, mCSP.IV)

            byt = Convert.FromBase64String(Value)

            ms = New MemoryStream
            cs = New CryptoStream(ms, ct, CryptoStreamMode.Write)
            cs.Write(byt, 0, byt.Length)
            cs.FlushFinalBlock()

            cs.Close()

            Return Encoding.UTF8.GetString(ms.ToArray())
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

        Return Nothing
    End Function

   Dim abc() As String
        Dim abcstr As String = "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z"
        abc = Split(abcstr, ",")
        Dim rand As New System.Random()


        Dim sn As String = ""
        For i As Int16 = 1 To 15
            sn = sn & abc(rand.Next(1, abc.Length))
        Next
        Response.Write(sn & "<br>")
        Response.Write(SetSn(sn) & "<br>")
        Response.Write(DeSetSn(SetSn(sn)) & "<br>")

  评论这张
 
阅读(403)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017