在C#中直接引用加密類庫比在C中要方便和快速
des_demo
using System;
using System
using System
using System
public class EncryptStringDES {
public static void Main(String[] args) {
if (args
Console
return;
}
// 使用UTF
UTF
byte[] inputByteArray = utf
// 方式一
DES des = DES
SymmetricStreamEncryptor sse = des
Byte[] key = {
Byte[] IV = {
des
des
// 建立加密流
SymmetricStreamEncryptor sse = des
CryptoMemoryStream cms = new CryptoMemoryStream(); // 將SymmetricStreamEncryptor流中的加密數據輸出到CryptoMemoryStream中
sse
// 加密完畢
sse
sse
byte[] encryptedData = cms
Console
for (int i =
Console
}
Console
SymmetricStreamDecryptor ssd = des
cms = new CryptoMemoryStream();
ssd
ssd
ssd
byte[] decryptedData = cms
char[] decryptedCharArray = utf
Console
Console
Console
}
} 編譯
D:\csharp>csc des_demo
Microsoft (R) C# Compiler Version
Copyright (C) Microsoft Corp
D:\csharp>des_demo
加密結果
From:http://tw.wingwit.com/Article/program/net/201311/12196.html