A class that can be used for encryption/decryption

Source: Internet
Author: User
It can be used to encrypt/decrypt database users and passwords.
Using System;
Using System. IO;
Using System. Text;
Using System. Security. Cryptography;
Namespace Common
{
/// <Summary>
/// Summary of SecurityService.
/// </Summary>
Public class SecurityService
{
Static protected Byte [] byteKey = {125, 14, 45, 67,112, 79, 77, 99, 37,104, 13, 9,118, 51, 87,108 };
Static protected Byte [] byteIV = {86, 19, 79, 15, 72, 58,117, 45 };
Static public string encryption ricencrypt (String sPlainText)
{
Byte [] bytePlaintext;
MemoryStream EncryptedStream;
ICryptoTransform Encryptor;
CryptoStream TheCryptoStream;
If (sPlainText = "") return "";
BytePlaintext = Encoding. ASCII. GetBytes (sPlainText );
EncryptedStream = new MemoryStream (sPlainText. Length );
Encryptor = GetEncryptor ();
TheCryptoStream = new CryptoStream (EncryptedStream, Encryptor, CryptoStreamMode. Write );
TheCryptoStream. Write (bytePlaintext, 0, bytePlaintext. Length );
TheCryptoStream. FlushFinalBlock ();
TheCryptoStream. Close ();
Return Convert. ToBase64String (EncryptedStream. ToArray ());
} // End Function
Static public string encryption ricdecrypt (String sEncryptedText)
{
Byte [] byteEncrypted;
MemoryStream PlaintextStream;
ICryptoTransform Decryptor;
CryptoStream TheCryptoStream;
If (sEncryptedText = "") return "";
ByteEncrypted = Convert. FromBase64String (sEncryptedText. Trim ());

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.