1. Public Class Cls_JM
  2.  
  3. '使用
  4. 'Dim Jm As New Cls_JM(2)
  5. 'Dim strTmp As String
  6.  
  7. 'Jm.jiemi(strTmp)
  8. 'Jm.Jiami(strTmp)
  9.  
  10. Private TripleDes As New System.Security.Cryptography.TripleDESCryptoServiceProvider
  11.  
  12. Private Function TruncateHash(ByVal key As String, ByVal length As Integer) As Byte()
  13. Dim sha1 As New System.Security.Cryptography.SHA1CryptoServiceProvider ' Hash the key.
  14. Dim keyBytes() As Byte = System.Text.Encoding.Unicode.GetBytes(key)
  15. Dim hash() As Byte = sha1.ComputeHash(keyBytes) ' Truncate or pad the hash.
  16. ReDim Preserve hash(length - )
  17. Return hash
  18. End Function
  19.  
  20. Sub New(ByVal key As String) ' Initialize the crypto provider.
  21. TripleDes.Key = TruncateHash(key, TripleDes.KeySize \ )
  22. TripleDes.IV = TruncateHash("", TripleDes.BlockSize \ )
  23. End Sub
  24.  
  25. Public Function jiami(ByVal plaintext As String) As String ' Convert the plaintext string to a byte array.
  26. Dim plaintextBytes() As Byte = System.Text.Encoding.Unicode.GetBytes(plaintext) ' Create the stream.
  27. Dim ms As New System.IO.MemoryStream ' Create the encoder to write to the stream.
  28. 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.
  29. encStream.Write(plaintextBytes, , plaintextBytes.Length)
  30. encStream.FlushFinalBlock() ' Convert the encrypted stream to a printable string.
  31. Return Convert.ToBase64String(ms.ToArray)
  32. End Function
  33.  
  34. Public Function jiemi(ByVal encryptedtext As String) As String ' Convert the encrypted text string to a byte array.
  35. Dim encryptedBytes() As Byte = Convert.FromBase64String(encryptedtext) ' Create the stream.
  36. Dim ms As New System.IO.MemoryStream ' Create the decoder to write to the stream.
  37. 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.
  38. decStream.Write(encryptedBytes, , encryptedBytes.Length)
  39. decStream.FlushFinalBlock() ' Convert the plaintext stream to a string.
  40. Return System.Text.Encoding.Unicode.GetString(ms.ToArray)
  41. End Function
  42.  
  43. 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. Helpers\FastCache

    Helpers\FastCache phpFastCache is a high-performance, distributed object caching system, generic in ...

  2. Spring 中jdbcTemplate 实现执行多条sql语句

    说一下Spring框架中使用jdbcTemplate实现多条sql语句的执行: 很多情况下我们需要处理一件事情的时候需要对多个表执行多个sql语句,比如淘宝下单时,我们确认付款时要对自己银行账户的表里 ...

  3. Android进阶笔记05:View、SurfaceView 和GLSurfaceView 的关系和区别

    1.  Android游戏当中主要的除了控制类外就是显示类View.SurfaceView是从View基类中派生出来的显示类.android游戏开发中常用的三种视图是:    (1) view.Sur ...

  4. mysql颠覆实战笔记(二)-- 用户登录(一):唯一索引的妙用

    版权声明:笔记整理者亡命小卒热爱自由,崇尚分享.但是本笔记源自www.jtthink.com(程序员在囧途)沈逸老师的<web级mysql颠覆实战课程 >.如需转载请尊重老师劳动,保留沈逸 ...

  5. 为Mono安装MySql连接驱动

    为Mono安装MySql连接驱动(转) 2013 年 1 月 24 日.NETmono.MySql DOTNET and Mono by default only support database c ...

  6. git workflows

    https://www.atlassian.com/git/tutorials/comparing-workflows Comparing Workflows The array of possibl ...

  7. Mac下批量打包

    两种方式: 第一种:有源码 这种方式比较 简单.利用ant打包.直接shell脚本修改 配置渠道号的文件.我们目前是用的umeng的.在AndroidManifest.xml里.提供一个简单的修改渠道 ...

  8. HDOJ2021发工资咯:)

    发工资咯:) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  9. Contoso 大学 - 使用 EF Code First 创建 MVC 应用

    原文 Contoso 大学 - 使用 EF Code First 创建 MVC 应用 Contoso 大学 Web 示例应用演示了如何使用 EF 技术创建 ASP.NET MVC 应用.示例中的 Co ...

  10. Swift中的循环语句

    循环语句能够使程序代码重复执行.Swift编程语言支持4种循环构造类型:while.do while.for和for in.for和while循环是在执行循环体之前测试循环条件,而do while是在 ...