Public Class Cls_JM

    '使用
'Dim Jm As New Cls_JM(2)
'Dim strTmp As String 'Jm.jiemi(strTmp)
'Jm.Jiami(strTmp) Private TripleDes As New System.Security.Cryptography.TripleDESCryptoServiceProvider Private Function TruncateHash(ByVal key As String, ByVal length As Integer) As Byte()
Dim sha1 As New System.Security.Cryptography.SHA1CryptoServiceProvider ' Hash the key.
Dim keyBytes() As Byte = System.Text.Encoding.Unicode.GetBytes(key)
Dim hash() As Byte = sha1.ComputeHash(keyBytes) ' Truncate or pad the hash.
ReDim Preserve hash(length - )
Return hash
End Function Sub New(ByVal key As String) ' Initialize the crypto provider.
TripleDes.Key = TruncateHash(key, TripleDes.KeySize \ )
TripleDes.IV = TruncateHash("", TripleDes.BlockSize \ )
End Sub Public Function jiami(ByVal plaintext As String) As String ' Convert the plaintext string to a byte array.
Dim plaintextBytes() As Byte = System.Text.Encoding.Unicode.GetBytes(plaintext) ' Create the stream.
Dim ms As New System.IO.MemoryStream ' Create the encoder to write to the stream.
Dim encStream As New System.Security.Cryptography.CryptoStream(ms, TripleDes.CreateEncryptor(), System.Security.Cryptography.CryptoStreamMode.Write) ' Use the crypto stream to write the byte array to the stream.
encStream.Write(plaintextBytes, , plaintextBytes.Length)
encStream.FlushFinalBlock() ' Convert the encrypted stream to a printable string.
Return Convert.ToBase64String(ms.ToArray)
End Function Public Function jiemi(ByVal encryptedtext As String) As String ' Convert the encrypted text string to a byte array.
Dim encryptedBytes() As Byte = Convert.FromBase64String(encryptedtext) ' Create the stream.
Dim ms As New System.IO.MemoryStream ' Create the decoder to write to the stream.
Dim decStream As New System.Security.Cryptography.CryptoStream(ms, TripleDes.CreateDecryptor(), System.Security.Cryptography.CryptoStreamMode.Write) ' Use the crypto stream to write the byte array to the stream.
decStream.Write(encryptedBytes, , encryptedBytes.Length)
decStream.FlushFinalBlock() ' Convert the plaintext stream to a string.
Return System.Text.Encoding.Unicode.GetString(ms.ToArray)
End Function End Class

VB.Net 字符串加密类的更多相关文章

  1. Dotfuscator可以实现混淆代码、变量名修改、字符串加密

    C#编写的代码如果不进行一定程度的混淆和加密,那么是非常容易被反编译进行破解的,特别是对于一些商业用途的C#软件来说,因为盯着的人多,更是极易被攻破.使用VS自带的Dotfuscator可以实现混淆代 ...

  2. C#中常用的字符串加密,解密方法封装,包含只加密,不解密的方法

    //方法一//须添加对System.Web的引用//using System.Web.Security;/// <summary>/// SHA1加密字符串/// </summary ...

  3. C# 字符串加密解密方法

    这个是加密的算法的命名空间,使用加密算法前要引用该程序集  System.Security.Cryptography using System;using System.Data;using Syst ...

  4. OD学习笔记10:一个VB程序的加密和解密思路

    前边,我们的例子中既有VC++开发的程序,也有Delphi开发的程序,今天我们给大家分析一个VB程序的加密和解密思路. Virtual BASIC是由早期DOS时代的BASIC语言发展而来的可视化编程 ...

  5. Java对字符串加密并返回星号※

     If you don't look back, you'll never know I waiting for you behind you. Java对字符串加密并返回星号※ PasswordUt ...

  6. C# DES加密类,16位的加密。

    这个加密类是与java写的DES加密不同时,自己写的,最后与Java的加密相同了,解决了加密后不同的问题. 可以直接调用里面的加密和解密的方法. using System; using System. ...

  7. JAVA中简单的MD5加密类(MD5Utils)

    MD5加密分析:   JDK API:   获取对象的API:   加密的API:   package cn.utils; import java.security.MessageDigest; im ...

  8. C#通用类库整理--字符串处理类

    在程序开发中通常需要将字符串转为自己想要的结果,以下三个类库主要实现: 1.GetStrArray(string str, char speater, bool toLower)  把字符串按照分隔符 ...

  9. C# 字符串处理类

    using System;using System.Collections.Generic;using System.Text;using System.Text.RegularExpressions ...

随机推荐

  1. 小白日记26:kali渗透测试之提权(六)--收集敏感信息,隐藏痕迹

    提权后操作 提权之后,要收集目标系统的重要信息LINUX /etc/resolv.conf       #查看DNS配置,是否可以进行DNS篡改或劫持 /etc/passwd         #存放账 ...

  2. Android(java)学习笔记93:Android布局详解之一:FrameLayout

    FrameLayout是最简单的布局了.所有放在布局里的控件,都按照层次堆叠在屏幕的左上角.后加进来的控件覆盖前面的控件. 在FrameLayout布局里,定义任何空间的位置相关的属性都毫无意义.控件 ...

  3. Zabbix Api的使用

    API使用 zabbix官网文档:https://www.zabbix.com/documentation/2.2/manual/api, Zabbix API是基于JSON-RPC 2.0规格,具体 ...

  4. cogs 餐巾 461(贪心)

    /*虽然这暴力剪了又剪 改了又改 还是初始的20分...*/ #include<iostream> #include<cstdio> #include<cstring&g ...

  5. Win7 32bit(x86)/64bit(x64) 完整安装版(非GHOST版本)

    Windows7 32bit 旗舰iso格式完整安装镜像 百度云盘:http://pan.baidu.com/s/1bpjLPs Windows7 64bit 旗舰iso格式完整安装镜像 百度云盘:h ...

  6. Web前端学习笔记1

    Day1. 1.Windows常用快捷键. 快捷键 功能 ctrl+c 复制 ctrl+v 粘贴 ctrl+x 剪切(复制和剪切后都可以粘贴) ctrl+a 全选 ctrl+s 保存 ctrl+tab ...

  7. JMS - 消息确认

    消息确认机制 消息确认协议是保证消息传送的关键所在,同时,支持确认也是 JMS API 语义的要求.以下将分别从消息生产者.消息服务器.消息消费者的角度,来考察消息确认机制. 从消息生产者的角度考察 ...

  8. Jersey(1.19.1) - Life-cycle of Root Resource Classes

    By default the life-cycle of root resource classes is per-request, namely that a new instance of a r ...

  9. C#几个经常犯错误汇总

    在我们平常编程中,时间久了有时候会形成一种习惯性的思维方式,形成固有的编程风格,但是有些地方是需要斟酌的,即使是一个很小的错误也可能会导致昂贵的代价,要学会善于总结,从错误中汲取教训,尽量不再犯同样错 ...

  10. 让无线网卡同时工作在 AP 和 STA 模式

    这个帖子里的方法有点过时了,不推荐继续使用. 有的时候会碰到这么一种情况,带着电脑和手机出去蹭网,无奈只有一个账号,手机上了电脑就没得用了,电脑用了手机就上不了网.如果能用电脑连接 Wifi 然后再开 ...