VB.Net 字符串加密类
- 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 字符串加密类的更多相关文章
- Dotfuscator可以实现混淆代码、变量名修改、字符串加密
C#编写的代码如果不进行一定程度的混淆和加密,那么是非常容易被反编译进行破解的,特别是对于一些商业用途的C#软件来说,因为盯着的人多,更是极易被攻破.使用VS自带的Dotfuscator可以实现混淆代 ...
- C#中常用的字符串加密,解密方法封装,包含只加密,不解密的方法
//方法一//须添加对System.Web的引用//using System.Web.Security;/// <summary>/// SHA1加密字符串/// </summary ...
- C# 字符串加密解密方法
这个是加密的算法的命名空间,使用加密算法前要引用该程序集 System.Security.Cryptography using System;using System.Data;using Syst ...
- OD学习笔记10:一个VB程序的加密和解密思路
前边,我们的例子中既有VC++开发的程序,也有Delphi开发的程序,今天我们给大家分析一个VB程序的加密和解密思路. Virtual BASIC是由早期DOS时代的BASIC语言发展而来的可视化编程 ...
- Java对字符串加密并返回星号※
If you don't look back, you'll never know I waiting for you behind you. Java对字符串加密并返回星号※ PasswordUt ...
- C# DES加密类,16位的加密。
这个加密类是与java写的DES加密不同时,自己写的,最后与Java的加密相同了,解决了加密后不同的问题. 可以直接调用里面的加密和解密的方法. using System; using System. ...
- JAVA中简单的MD5加密类(MD5Utils)
MD5加密分析: JDK API: 获取对象的API: 加密的API: package cn.utils; import java.security.MessageDigest; im ...
- C#通用类库整理--字符串处理类
在程序开发中通常需要将字符串转为自己想要的结果,以下三个类库主要实现: 1.GetStrArray(string str, char speater, bool toLower) 把字符串按照分隔符 ...
- C# 字符串处理类
using System;using System.Collections.Generic;using System.Text;using System.Text.RegularExpressions ...
随机推荐
- Helpers\FastCache
Helpers\FastCache phpFastCache is a high-performance, distributed object caching system, generic in ...
- Spring 中jdbcTemplate 实现执行多条sql语句
说一下Spring框架中使用jdbcTemplate实现多条sql语句的执行: 很多情况下我们需要处理一件事情的时候需要对多个表执行多个sql语句,比如淘宝下单时,我们确认付款时要对自己银行账户的表里 ...
- Android进阶笔记05:View、SurfaceView 和GLSurfaceView 的关系和区别
1. Android游戏当中主要的除了控制类外就是显示类View.SurfaceView是从View基类中派生出来的显示类.android游戏开发中常用的三种视图是: (1) view.Sur ...
- mysql颠覆实战笔记(二)-- 用户登录(一):唯一索引的妙用
版权声明:笔记整理者亡命小卒热爱自由,崇尚分享.但是本笔记源自www.jtthink.com(程序员在囧途)沈逸老师的<web级mysql颠覆实战课程 >.如需转载请尊重老师劳动,保留沈逸 ...
- 为Mono安装MySql连接驱动
为Mono安装MySql连接驱动(转) 2013 年 1 月 24 日.NETmono.MySql DOTNET and Mono by default only support database c ...
- git workflows
https://www.atlassian.com/git/tutorials/comparing-workflows Comparing Workflows The array of possibl ...
- Mac下批量打包
两种方式: 第一种:有源码 这种方式比较 简单.利用ant打包.直接shell脚本修改 配置渠道号的文件.我们目前是用的umeng的.在AndroidManifest.xml里.提供一个简单的修改渠道 ...
- HDOJ2021发工资咯:)
发工资咯:) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- Contoso 大学 - 使用 EF Code First 创建 MVC 应用
原文 Contoso 大学 - 使用 EF Code First 创建 MVC 应用 Contoso 大学 Web 示例应用演示了如何使用 EF 技术创建 ASP.NET MVC 应用.示例中的 Co ...
- Swift中的循环语句
循环语句能够使程序代码重复执行.Swift编程语言支持4种循环构造类型:while.do while.for和for in.for和while循环是在执行循环体之前测试循环条件,而do while是在 ...