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 ...
随机推荐
- Linux 学习笔记 cp 和 ln
最近在重温大学的经典课程:Linux.每天工作之余的时间,坐在家里的阳台上,简简单单的纪录一些基本的知识点,对我来说,既温暖又难得. 有朋友问我关于cp和ln建立符号链接(软链接)和硬链接的一些问题, ...
- cocos2d-x lua 使用自定义消息EventCustom
cocos2d-x lua 使用自定义消息EventCustom version: cocos2d-x 3.6 1.发送消息 -- post message -- event将会被传递给消息接收函数, ...
- Android进阶笔记14:ListView篇之ListView性能优化
1. 首先思考一个问题ListView如何才能提高效率 ? 当convertView为空时候,用setTag()方法为每个View绑定一个存放控件的ViewHolder对象.当convertView不 ...
- MYSQL基础笔记(三)-表操作基础
数据表的操作 表与字段是密不可分的. 新增数据表 Create table [if not exists] 表名( 字段名 数据类型, 字段名 数据类型, 字段n 数据类型 --最后一行不需要加逗号 ...
- 网站安全通用防护代码(C#版本源码提供)
每一个开发者都会意识到,网站发布之前,需要进行安全检查. 那么如何拦截攻击者注入恶意代码?如何防御诸如跨站脚本攻击(XSS).SQL注入攻击等恶意攻击行为? 针对目前常见的一些安全问题,结合目前一些常 ...
- Vim编辑器的常用快捷键.
Linux中的文本操作离不开Vim编辑器的使用. Vim编辑器的使用相对门槛较高.需要挺长一段时间的适应. 总结一些Vim使用过程中常用的命令(这些命令基本上都是在vim的命令模式下使用) 1.跳转到 ...
- 一次配置jdk环境变量的感悟
开发java也一年多了,昨日一次偶然的机会,想在dos命令下执行一个程序,发现在 命令行输入 javac Test.java的时候,竟然提示javac不是内部命令, 之后输入 java ,也提示不是内 ...
- C#算法基础之希尔排序
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- Linux C编程--格式化I/O
printf(格式控制,输入表列) 例:printf("%d%d",a,b) (1)d格式符:输出一个有符号的十进制整数 (2)c格式符:输出一个字符 (3)s格式符:输出一个字符 ...
- win7下将主分区转换成逻辑分区
在了解怎么转换之前,先搞清楚主分区,扩展分区,逻辑分区的基本概念. 主分区,也称为主磁盘分区,和扩展分区.逻辑分区一样,是一种分区类型.主分区中不能再划分其他类型的分区,因此每个主分区都相当于一个逻辑 ...