private void Encrypt() { // getting the key byte[] key = EncryptionUtils.VerifyKeyLength(encryptSeed, trueBase64, base64UrlSafe); // using the key to create the seed if (trueBase64) { if (base64UrlSafe) { encryptSeed = EncryptionUtils.Base64Rfc4686Encode(Convert.ToBase64String(key)); } else { encryptSeed = Convert.ToBase64String(key); } } else { encryptSeed = EncryptionUtils.ByteArrayToHexString(key); } // creating the byte array byte[] encryptedString = EncryptionUtils.EncryptStringToBytes(encryptPlainText, key); // writing the byte array WriteConfig(encryptedString); // getting the cipher text string result = ""; if (trueBase64) { if (base64UrlSafe) { result = EncryptionUtils.Base64Rfc4686Encode(Convert.ToBase64String(encryptedString)); } else { result = Convert.ToBase64String(encryptedString); } } else { result = EncryptionUtils.ByteArrayToHexString(encryptedString); } // displaying the cipher text encryptCipherText = result; }
private void Decrypt() { // getting the key byte[] key = EncryptionUtils.VerifyKeyLength(encryptSeed, trueBase64, base64UrlSafe); // using the key to create the seed if (trueBase64) { if (base64UrlSafe) { encryptSeed = EncryptionUtils.Base64Rfc4686Encode(Convert.ToBase64String(key)); } else { encryptSeed = Convert.ToBase64String(key); } } else { encryptSeed = EncryptionUtils.ByteArrayToHexString(key); } // getting the byte[] byte[] encryptedString = ReadConfig(); // getting the cipher text string result = ""; if (trueBase64) { if (base64UrlSafe) { result = EncryptionUtils.Base64Rfc4686Encode(Convert.ToBase64String(encryptedString)); } else { result = Convert.ToBase64String(encryptedString); } } else { result = EncryptionUtils.ByteArrayToHexString(encryptedString); } // displaying the cipher text decryptCipherText = result; /* * if (mTrueBase64) * { * if (mBase64UrlSafe) * { * encryptedString = Convert.FromBase64String(EncryptionUtils.base64Rfc4686Decode(mCipherText)); * } * else * { * encryptedString = Convert.FromBase64String(mCipherText); * } * } * else * { * encryptedString = EncryptionUtils.hexStringToByteArray_Rev4(mCipherText); * } */ // getting the plain text string res = EncryptionUtils.DecryptStringFromBytes(encryptedString, key); if (base64UrlSafe) { res = EncryptionUtils.Base64Rfc4686Encode(res); } decryptPlainText = res; }