| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 982 人关注过本帖
标题:[分享]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
快速回复:[分享]DES加密算法
数据加载中...
 
   



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

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