CSharp examples for System.Security.Cryptography:Encrypt Decrypt
Encrypts a string with Rijndael
using System.Text; using System.Security.Cryptography; using System;// w w w. j ava2s. c o m public class Main{ /// <summary> /// Encrypts a string with Rijndael /// </summary> /// <param name="plainText">String to encrypt</param> /// <returns>Encrypted string</returns> public static string Encrypt(string plainText) { var rijndael = new RijndaelManaged(); rijndael.Key = Convert.FromBase64String(key); rijndael.IV = Convert.FromBase64String(IV); byte[] buffer = Encoding.UTF8.GetBytes(plainText); return Convert.ToBase64String(rijndael.CreateEncryptor().TransformFinalBlock(buffer, 0, buffer.Length)); } }