惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Docker
人人都是产品经理
人人都是产品经理
小众软件
小众软件
博客园 - Franky
WordPress大学
WordPress大学
Jina AI
Jina AI
Google DeepMind News
Google DeepMind News
I
InfoQ
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
F
Fortinet All Blogs
博客园 - 【当耐特】
IT之家
IT之家
G
Google Developers Blog
J
Java Code Geeks
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
云风的 BLOG
云风的 BLOG
Recent Announcements
Recent Announcements
有赞技术团队
有赞技术团队
V
Visual Studio Blog
U
Unit 42
阮一峰的网络日志
阮一峰的网络日志
月光博客
月光博客
GbyAI
GbyAI
雷峰网
雷峰网

博客园 - N/A2011

Managing Hierarchical Data in MySQL php soapclient with wsse 转贴 MySQL Multiple Result Procs in PHP 转贴 jQuery Datepicker by Example 转贴 Using MySQL Stored Procedures with PHP mysql/mysqli/pdo php generate pdf open office (java) ant + emma + junit Copy all files recursively from one folder to another RecursiveFileFinder 转贴: 怎样找第一份工作 PerformanceCounter in .net Trace in .net Logger in .net 转贴: 傅立叶级数(Fourier Series) 推导 CAS in .net Access Control List in .net User and Data Security in .net Unmanaged code in .net
Encrypting and Decrypting in .net
N/A2011 · 2009-05-19 · via 博客园 - N/A2011

VB.NET:

Imports System.Security.Cryptography
Imports System.IO
Imports System.TextModule Module1Sub Main()
        
Dim inFileName As String = "C:\in.txt"
        
Dim outFileName As String = "C:\out.txt"
        
Dim password As String = "Joey"
        
Dim salt As Byte() = Encoding.Unicode.GetBytes("Salt adds to left spaces")
        
Dim key As New Rfc2898DeriveBytes(password, salt)
        
Dim rm As New RijndaelManaged()
        rm.Key 
= key.GetBytes(rm.KeySize / 8)
        rm.IV 
= key.GetBytes(rm.BlockSize / 8)
        
Dim inFile As New FileStream(inFileName, FileMode.Open, FileAccess.Read)
        
Dim data(inFile.Length - 1As Byte
        inFile.Read(data, 
0, data.Length)
        
Dim encryptor As ICryptoTransform = rm.CreateEncryptor
        
Dim outFile As New FileStream(outFileName, FileMode.OpenOrCreate, FileAccess.Write)
        
Dim stream As New CryptoStream(outFile, encryptor, CryptoStreamMode.Write)
        stream.Write(data, 
0, data.Length)
        stream.Close()
        outFile.Close()
        inFile.Close()
    
End SubEnd Module

C#:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using System.IO;namespace EncryptingAndDecryptingCS
{
    
class Program
    {
        
static void Main(string[] args)
        {
            
string inFileName = @"C:\in.txt";
            
string outFileName = @"C:\out.txt";
            
string password = "Joey";
            
byte[] salt = Encoding.Unicode.GetBytes("Salt adds to left spaces");
            Rfc2898DeriveBytes key 
= new Rfc2898DeriveBytes(password, salt);
            RijndaelManaged rm 
= new RijndaelManaged();
            rm.Key 
= key.GetBytes(rm.KeySize / 8);
            rm.IV 
= key.GetBytes(rm.BlockSize / 8);
            FileStream inFile 
= new FileStream(inFileName, FileMode.Open, FileAccess.Read);
            
byte[] data = new byte[inFile.Length];
            inFile.Read(data, 
0, data.Length);
            ICryptoTransform encryptor 
= rm.CreateEncryptor();
            FileStream outFile 
= new FileStream(outFileName, FileMode.OpenOrCreate, FileAccess.Write);
            CryptoStream stream 
= new CryptoStream(outFile, encryptor, CryptoStreamMode.Write);
            stream.Write(data, 
0, data.Length);
            stream.Close();
            outFile.Close();
            inFile.Close();
        }
    }
}