This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Returns the IV needed for decryption. 16 Bytes | |
/// </summary> | |
/// <param name="base64_cipher_text"></param> | |
/// <returns></returns> | |
public static byte[] RetrieveIv(string base64_cipher_text) | |
{ | |
// Just 16 the first bytes | |
// 16 not divisable by 3 (4 characters per 3 bytes) | |
// 4 -> 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Retivers the cipher text without the IV | |
/// </summary> | |
/// <param name="base64_cipher_text"></param> | |
/// <returns></returns> | |
public static byte[] RetrieveCipher(string base64_cipher_text) | |
{ | |
byte[] cipher_binary = Convert.FromBase64String(base64_cipher_text); | |
var length = cipher_binary.Length - 16; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Decrypts the cipher text. | |
/// </summary> | |
/// <param name="cipherText"></param> | |
/// <param name="Key"></param> | |
/// <param name="IV"></param> | |
/// <returns></returns> | |
static string DecryptStringFromBytes_Aes(byte[] cipherText, byte[] Key, byte[] IV) | |
{ | |
// Check arguments. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void Decrypt() | |
{ | |
using (AesManaged myAes = new AesManaged()) | |
{ | |
var protected_string = "W+YnphJ2T8pH4X+FNTwZvFPab+R4wRbZg/6HuyZ8Ese15LYp1UJLs7HvmIco4w6A"; | |
byte[] protected_bytes = RetrieveCipher(protected_string); | |
// Encryption key | |
var encrption_key = Convert.FromBase64String(Constants.s_encrption_key); | |
// IV | |
var byte_IV = RetrieveIv(protected_string); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Newtonsoft.Json; | |
using System; | |
using System.IO; | |
using System.IO.Compression; | |
using System.Security.Cryptography; | |
using System.Text; | |
namespace ManagedAES | |
{ | |
/// <summary> |