Vb教程 Vb.net教程 Vfp教程 C/C++教程 Vc/Vc++教程 Delphi教程 Java教程 Powerbuilder
  杀毒频道 | 短信频道 | 网络电视 | 论文中心 | 学上网 | 学软件 | 网页特效 | 电脑基础 | 论坛  
  NCRE | 软考 | CET | 职称英语 | 司法考试 | 报关员 | 公务员 | CATTI | CPA考试  
  Html教程 | Css教程 | Xml教程 | Asp教程 | Asp.net | Php教程 | Jsp教程 | Linux教程 | QQ技巧  
Photoshop Illustrator ImageReady Maya教程 3D Max教程 Lightscape Coredraw教程 Authorware Autocad教程 Freehand教程
Access教程 Mysql教程 Sql server Oracle教程 Word教程 Excel教程 Powerpoint Frontpage Asp.net源码 Php源代码
Flash教程 Fireworks Dreamweaver C#教程 outlook教程 系统安装 vbscript教程 Javascript Jsp源代码 Asp源代码
您的位置:首页 >> Vb.net教程 >> 正文

字符串加解密的类

文章来源:互联网

'EZ_Crypt.vb(字符串加密和解密类)

'参考Namespace
Imports System
Imports Microsoft.VisualBasic
Imports System.Collections
Imports System.Configuration

Namespace Security
    Public Class Crypt
    '加密字符串
        Public Function Encrypt(ByVal PlainStr As String, ByVal key As String) As String
            Dim strChar, KeyChar, NewStr As String
            Dim Pos As Integer
            Dim i, intLen As Integer
            Dim Side1, Side2 As String
            Pos = 1

            For i = 1 To Len(PlainStr)
                strChar = Mid(PlainStr, i, 1)
                KeyChar = Mid(key, Pos, 1)
                NewStr = NewStr & Chr(Asc(strChar) Xor Asc(KeyChar))
                If Pos = Len(key) Then Pos = 0
                Pos = Pos + 1
            Next

            If Len(NewStr) Mod 2 = 0 Then
                Side1 = StrReverse(Left(NewStr, (Len(NewStr) / 2)))
                Side2 = StrReverse(Right(NewStr, (Len(NewStr) / 2)))
                NewStr = Side1 & Side2
            End If

            Encrypt = NewStr
        End Function

    '解密字符串
        Public Function Decrypt(ByVal PlainStr As String, ByVal key As String) As String
            Dim strChar, KeyChar, NewStr As String
            Dim Pos As Integer
            Dim i As Integer
            Dim Side1 As String
            Dim Side2 As String
            Pos = 1

            If Len(PlainStr) Mod 2 = 0 Then
                Side1 = StrReverse(Left(PlainStr, (Len(PlainStr) / 2)))
                Side2 = StrReverse(Right(PlainStr, (Len(PlainStr) / 2)))
                PlainStr = Side1 & Side2
            End If

            For i = 1 To Len(PlainStr)
                strChar = Mid(PlainStr, i, 1)
                KeyChar = Mid(key, Pos, 1)
                NewStr = NewStr & Chr(Asc(strChar) Xor Asc(KeyChar))
                If Pos = Len(key) Then Pos = 0
                Pos = Pos + 1
            Next

            Decrypt = NewStr
        End Function
    End Class
End Namespace

[返回]

编程语言 web开发 数据库 网络技术 操作系统 服务器 网页设计 图形设计 办公软件 常用软件 学电脑

Copyright© www.bianceng.cn Powered by 编程入门网 All Rights Reserved.
关于本站 | 版权声明 | 联系我们 | 友情链接 |
编程入门网 版权所有