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. iOS 除去图片的白色背景(接近白色),或者其它颜色的替换,获取像素点的ARGB值

    iOS 除去图片的白色背景(接近白色),或者其它颜色的替换 方法如下: //去除图片的白色背景 + (UIImage*) imageToTransparent:(UIImage*) image { / ...

  2. proxy代理类

    package cn.hncu.proxy.rent; import java.lang.reflect.InvocationHandler;import java.lang.reflect.Meth ...

  3. Android(java)学习笔记108:通过反射获取私有构造方法并且使用

    反射获取私有构造方法并且使用: 1.获取字节码文件.class对象:          Class c = Class.forName("cn.itcast_01.Person") ...

  4. 手把手教你使用Size Class

    在 iOS8 中,我们不用再像以前那样,一个页面新建多个 xib 文件来适配不同类型的屏幕,现在我们可以把各种尺寸屏幕的适配工作放在一个文件中完成,然后可以通过不同类别的 Size 来定制各种尺寸的界 ...

  5. MongoDB,HDFS, Spark to 电影推荐

    http://www.infoq.com/cn/news/2014/12/mongdb-spark-movie-recommend MovieWeb是一个电影相关的网站,它提供的功能包括搜索电影信息. ...

  6. Servlet & JSP - HttpSession

    关于 Session 的内容,参考 HTTP - Session 机制 创建和检索 HttpSession 通过 HttpServletRequest.getSession 方法可以获取 HttpSe ...

  7. MyBatis(3.2.3) - Configuring MyBatis using XML, Settings

    The default MyBatis global settings, which can be overridden to better suit application-specific nee ...

  8. Forms身份认证

    引言 大家都知道Http是无状态的协议,所以访问一个url,你并不能知道用户在之前是否已经登陆过.但是许多业务上的逻辑又离不开user的信息,这个时候就可以借助身份认证来记录当前user的登录状态.这 ...

  9. 每天一道LeetCode--119.Pascal's Triangle II(杨辉三角)

    Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...

  10. winform版简易http服务器

    传人url运行(url以/结尾,例如:http://localhost:8080/web/ 监听这个url// 在浏览器 中输入 http://localhost:8080/web/?name=tes ...