Created
March 13, 2021 10:17
-
-
Save muhaisen/116f3004faa02a447888358b5aaecf09 to your computer and use it in GitHub Desktop.
Gets the IV from Salesforce encryptWithManagedIV
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 | |
// ?? 18 | |
// (4 * 18) / 3 = 24 | |
// This will be 18 bytes long | |
base64_cipher_text = base64_cipher_text.Substring(0, 24); | |
// 18 bytes long | |
byte[] cipher_binary = Convert.FromBase64String(base64_cipher_text); | |
byte[] iv = new byte[16]; | |
// Take first 16 only and discard the left | |
Array.Copy(cipher_binary, 0, iv, 0, 16); | |
return iv; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment