Encryption && Decryption
来源:互联网 发布:yum install wget 编辑:程序博客网 时间:2024/05/22 12:59
using System;using System.IO;using System.Security.Cryptography;using System.Text;
<span style="white-space:pre"></span>public static class Encryption{#region Fieldsprivate static stringERROR = "Error \"{0}\" is not valid";private static byte[]RGBIV = new byte[] {0x19, 0x21, 0xA5, 0xbe, 0x11, 0xFF, 0x19, 0xD1};#endregion#region Methods/// <summary>/// Decrypt the text string using the salt/// </summary>/// <param name="text">The ecnrypted string to decrypt</param>/// <param name="salt">The salt to decrypt to text string</param>public static string Decrypt(string value, string key){if (string.IsNullOrEmpty(value)){return string.Empty;}else{byte[]inputByteArray = new byte[value.Length + 1];try{byte[]byKey = System.Text.Encoding.UTF8.GetBytes(key.Substring(0, RGBIV.Length));DESCryptoServiceProviderprovider = new DESCryptoServiceProvider();inputByteArray = Convert.FromBase64String(value);MemoryStreammemory = new MemoryStream();CryptoStreamstream = new CryptoStream(memory, provider.CreateDecryptor(byKey, RGBIV), CryptoStreamMode.Write);stream.Write(inputByteArray, 0, inputByteArray.Length);stream.FlushFinalBlock();Encoding encoding = Encoding.UTF8;return encoding.GetString(memory.ToArray());}catch{return string.Format(ERROR, value);}}}/// <summary>/// Encrypt the text string using the salt/// </summary>/// <param name="text">The text to encrypt</param>/// <param name="salt">The salt encrypt the text string</param>public static string Encrypt(string value, string key){if (string.IsNullOrEmpty(value)){return string.Empty;}else{try{byte[]bykey = Encoding.UTF8.GetBytes(key.Substring(0, RGBIV.Length)),InputByteArray = Encoding.UTF8.GetBytes(value);DESCryptoServiceProviderprovider = new DESCryptoServiceProvider();MemoryStreammemory = new MemoryStream();CryptoStreamstream = new CryptoStream(memory, provider.CreateEncryptor(bykey, RGBIV), CryptoStreamMode.Write);stream.Write(InputByteArray, 0, InputByteArray.Length);stream.FlushFinalBlock();return Convert.ToBase64String(memory.ToArray());}catch{return string.Format(ERROR, value);}}}#endregion}
0 0
- Encryption && Decryption
- XCrypt - encryption & decryption class wrapper.
- File Encryption and Decryption in C#
- Encryption/decryption system for USB storage devic
- password encryption and decryption with Base 64
- C code to implement RSA Algorithm(Encryption and Decryption)
- Encryption
- Cisco 'password 7' Decryption
- Password decryption in Weblogic
- AES128 Decryption异常
- HPU 1278: Decryption sequence
- Decryption sequence 【模拟】【思维】
- Decryption sequence [模拟]
- 1278: Decryption sequence
- XML Encryption
- encryption:gpg
- Encryption Technology
- DATA ENCRYPTION
- BIOS
- 2014多校5(1003)hdu4913(线段树区间操作)
- 主引导记录
- 打扫打扫的和规范化离开了
- HDU 1527 HDU 2177 威佐夫博奕
- Encryption && Decryption
- 设计模式——建造者
- [LeetCode] Valid Sudoku
- [NOI2005]瑰丽华尔兹
- Singleton Pattern
- dssdfs
- Palindrome Number
- dfgdfg秩序兴冲冲v
- 的说法了客户的疯狂荣恩替u非的公开了好想的疯狂