标题:[分享]DES加密算法
只看楼主
xhwxwk
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2005-8-24
 问题点数:0 回复次数:1 
[分享]DES加密算法

Imports System.IO Imports System.Text Imports System.Security.Cryptography

Public Class DES '--加密函数-- 'strEncrKey必须是8位或以上 Public Function Encrypt(ByVal data As String, ByVal strEncrKey As String) As String Try Dim bytes() As Byte = Encoding.Unicode.GetBytes(data) Dim byKey() As Byte = System.Text.Encoding.UTF8.GetBytes(strEncrKey.Substring(0, 8)) Dim iv() As Byte = {1, 2, 3, 4, 5, 6, 7, 8} Dim des As New DESCryptoServiceProvider Dim inputByteArray() As Byte = Encoding.UTF8.GetBytes(data) Dim ms As New MemoryStream Dim cs As New CryptoStream(ms, des.CreateEncryptor(byKey, iv), CryptoStreamMode.Write) cs.Write(inputByteArray, 0, inputByteArray.Length) cs.FlushFinalBlock() Return Convert.ToBase64String(ms.ToArray()) Catch MsgBox(Err.Description) Return "" End Try End Function

'--解密函数-- 'strEncrKey必须是8位或以上 Public Function Decrypt(ByVal data As String, ByVal strEncrKey As String) As String Try Dim bytes() As Byte = Encoding.Unicode.GetBytes(data) Dim byKey() As Byte = System.Text.Encoding.UTF8.GetBytes(strEncrKey.Substring(0, 8)) Dim iv() As Byte = {1, 2, 3, 4, 5, 6, 7, 8} Dim des As New DESCryptoServiceProvider Dim inputByteArray() As Byte = Encoding.UTF8.GetBytes(data) Dim ms As New MemoryStream inputByteArray = Convert.FromBase64String(data) Dim cs As New CryptoStream(ms, des.CreateDecryptor(byKey, iv), CryptoStreamMode.Write) cs.Write(inputByteArray, 0, inputByteArray.Length) cs.FlushFinalBlock() Return System.Text.Encoding.UTF8.GetString(ms.ToArray()) Catch MsgBox(Err.Description) Return "" End Try End Function End Class

搜索更多相关主题的帖子: DES 算法 分享 
2005-08-25 14:53
zephyr0703
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2010-5-13
得分:0 
谢谢诶

I think,so I be.
2010-05-13 10:56



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-26008-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.224381 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved