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 ...
随机推荐
- Windows 7中使用Eclipse 使用CDT and WinGW 开发C/C++(转载)
以前使用visual studio 2010编写C/C++,后来接触了Eclipse后,据说eclipse也可以编写C/C++,以前觉得Visual studio 2010还蛮不错的,也没有多大好奇心 ...
- Direct3D11-1 初始化
在使用一个东西之前,我们需要初始化他,好比汽车加油,手机充电.于是我们采取平时的编码习惯,试图写下如下代码 Direct3D11 _direct3d11; 事实上,我们 ...
- Direct3D-3 四元数
其实本来这篇文章是打算接上篇的各种变化矩阵的推导了,想了想,还是先讲四元数吧.本人的文章并不会提到欧拉角,因为我自己没弄懂欧拉角的万向锁问题. 很多人学习数学时,会有这样一个疑惑,这东 ...
- Android(java)学习笔记106-1:深入分析Java ClassLoader原理
1. 前言: Android中的动态加载机制能更好的优化我们的应用,同时实现动态的更新,这就便于我们管理我们的应用,通过插件化来减轻我们的内存以及CPU消耗,在不发布新版本的情况下能更新某些模块. 当 ...
- [翻译]Json.NET API-Linq to Json Basic Operator(基本操作)【转】
在Json.NET开源的组件的API文档中看到其中有个Linq To Json基本操作.详细看了其中API 中Linq to SQL命名空间下定义类方法.以及实现, 觉得参与Linq 来操作Json从 ...
- Kafka分布式消息模型
Kafka开发的主要初衷目标是构建一个用来处理海量日志,用户行为和网站运营统计等的数据处理框架.在结合了数据挖掘,行为分析,运营监控等需求的情况下,需要能够满足各种实时在线和批量离线处理应用场合对低延 ...
- Tomcat - DBCP 配置
1. Database configuration Create a new test user, a new database and a single test table. Your MySQL ...
- Linux 命令 - mkdir: 创建目录
命令格式 mkdir [OPTION]... DIRECTORY... 命令参数 -m, --mode=MODE 设置文件的模式,类似于 chmod 命令. -p, --parents 需要时创建指定 ...
- webBrowser1_DocumentCompleted不停被调用
原文地址:http://blog.csdn.net/shuishenlong/article/details/7950576 关于DocumentCompleted事件,MSDN给出的解释是在文档加载 ...
- Ibatis.net防Sql注入
sql注入是一个古老的话题了,但经常会被我们忽略.尤其是使用了ibatis.net之后. Ibatis.net框架对sql注入问题已经做了很好的防护,但经常由于开发人员使用不当,会造成sql的注入隐患 ...