Public class EncryptString {private static byte [] Key64 = {42, 16, 93,156, 78, 4,218, 32}; private static byte [] IV64 = {55,103,246, 79, 36, 99,167, 3}; private static byte [] Key192 = {42, 16, 93,156, 78, 4,218, 167, 26,250,155,112, 11,204,119, 35,184,197 }; private static byte [] IV192 = {55,103,246, 79, 36, 99,167, 184, 7,209, 13,145, 23,200, 58,173, 10,121,222}; public static String Encrypt (String valueString) {if (valueString! = "") {// Defines the Provider DESCryptoServiceProvider desprovider = new DESCryptoServiceProvider (); // defines the memory stream MemoryStream memoryStream = new MemoryStream (); // define the encryption stream CryptoStream cryptoStream = new CryptoStream (memoryStream, desprovider. createEncryptor (Key64, IV64), CryptoStreamMode. write); // define the Write IO stream StreamWriter writerStream = new StreamWriter (cryptoStream); // Write the encrypted writable stream writerStream. write (valueString); wr IterStream. flush (); cryptoStream. flushFinalBlock (); memoryStream. flush (); // return the encrypted string return (Convert. toBase64String (memoryStream. getBuffer (), 0, (int) memoryStream. length);} return (null);} public static String Decrypt (String valueString) {if (valueString! = "") {// Define DES Provider DESCryptoServiceProvider desprovider = new DESCryptoServiceProvider (); // Convert and decrypt the string to binary byte [] buffer = Convert. fromBase64String (valueString); // defines the memory stream MemoryStream memoryStream = new MemoryStream (); // defines the encryption stream CryptoStream cryptoStream = new CryptoStream (memoryStream, desprovider. createEncryptor (Key64, IV64), CryptoStreamMode. read); // define Read IO Stream StreamReader readerStream = new Stream Reader (cryptoStream); // return the decrypted string return (readerStream. readToEnd ();} return (null);} public static String EncryptTripleDES (String valueString) {if (valueString! = "") {// Defines the Provider TripleDESCryptoServiceProvider triprovider = new TripleDESCryptoServiceProvider (); // defines the memory stream MemoryStream memoryStream = new MemoryStream (); // define the encryption stream CryptoStream cryptoStream = new CryptoStream (memoryStream, triprovider. createEncryptor (Key192, IV192), CryptoStreamMode. write); // define the Write IO stream StreamWriter writerStream = new StreamWriter (cryptoStream); // Write the encrypted writable stream writerStream. wr Ite (valueString); writerStream. flush (); cryptoStream. flushFinalBlock (); memoryStream. flush (); // return the encrypted string return (Convert. toBase64String (memoryStream. getBuffer (), 0, (int) memoryStream. length);} return (null);} public static String DecryptTripleDES (String valueString) {if (valueString! = "") {// Define TripleDES's Provider TripleDESCryptoServiceProvider triprovider = new TripleDESCryptoServiceProvider (); // Convert and decrypt the string to binary byte [] buffer = Convert. fromBase64String (valueString); // defines the memory stream MemoryStream memoryStream = new MemoryStream (); // defines the encrypted stream CryptoStream cryptoStream = new CryptoStream (memoryStream, triprovider. createEncryptor (Key64, IV64), CryptoStreamMode. read); // define Read IO stream StreamReader readerStream = new StreamReader (cryptoStream); // return the decrypted string return (readerStream. readToEnd ();} return (null );}} |