欢迎光临
我们一直在努力

字符串加解密的类(VB.NET Source Code)-.NET教程,VB.Net语言

建站超值云服务器,限时71元/月

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

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 字符串加解密的类(VB.NET Source Code)-.NET教程,VB.Net语言
分享到: 更多 (0)

相关推荐

  • 暂无文章