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. 小白日记39:kali渗透测试之Web渗透-SQL手工注入(一)-检测方法

    SQL手工注入(一) SQL注入:通过把SQL命令插入到Web表单递交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意的SQL命令.[SQL注入原理] ##服务端程序将用户输入参数作为查询 ...

  2. 用 UIViewPropertyAnimator 编写动画

    [iOS 10 day by day] Day 1:开发 iMessage 的第三方插件 [iOS 10 day by day] Day 2:线程竞态检测工具 Thread Sanitizer < ...

  3. Maven学习小结(六 setting.xml详解[转])

    当Maven运行过程中的各种配置,例如pom.xml,不想绑定到一个固定的project或者要分配给用户时,我们使用settings.xml中的settings元素来确定这些配置.这包含了本地仓库位置 ...

  4. H.264编码之DCT变换原理

    DCT变换是一种与FFT变换紧密相连的数学运算,当函数为偶函数是,其傅立叶展开式只有余弦项,因些称为余弦变换,其离散化的过程称为DCT(离散余弦)变换.下面我们就推导下H.264的4x4整数DCT公式 ...

  5. Mysql打开日志信息

    还可参考博客:http://pangge.blog.51cto.com/6013757/1319304 1)怎么查看mysql是否启用了日志 mysql>show variables like ...

  6. 【数学,方差运用,暴力求解】hdu-5037 Galaxy (2014鞍山现场)

    话说这题读起来真费劲啊,估计很多人做不出来就是因为题读不懂...... 从题目中提取的几点关键点: 题目背景就是银河系(Rho Galaxy)中的星球都是绕着他们的质心(center of mass) ...

  7. 【数论,找规律】Uva 11526 - H(n)

    原来做过的题再看还是没想出来,看来当时必然没有真正理解.这次回顾感觉理解更透彻了. 网上的题解差不多都是一个版本,而且感觉有点扯.根据n=20猜出来的? 好吧哪能根据一个就猜到那么变态的公式.其实这题 ...

  8. Android 内存分析工具 MAT(Memory Analyzer Tool)

    如果使用DDMS确实发现了我们的程序中存在内存泄漏,那又如何定位到具体出现问题的代码片段,最终找到问题所在呢?如果从头到尾的分析代码逻辑,那肯定 会把人逼疯,特别是在维护别人写的代码的时候.这里介绍一 ...

  9. 一步步搭建自己的轻量级MVCphp框架-(一)什么是PHP框架以及MVC设计模式

    PHP框架 php框架对很多新手而言可能会觉得很难攀越,其实不然 ,只要知道一个框架的流程,明白原理了,基本类似框架都可以看懂,php框架真正的发展要从php5开始了,其实php4时代就有一些框架,但 ...

  10. CI加载流程小结

    无聊,决定水一把. CI(CodeIgniter)是我最早接触的一个框架,到现在也只是用了其中一点零碎的方法.一直想对其流程做个小结,却总是因各种各样的“理由”挨着.看见别人图表齐上阵,没那耐心,就从 ...