/// <summary> /// /// The encryption format is a JSON-encoded EcEncryptedMessageAesCbcHmacSha256. /// </summary> /// <param name="value">The value to store encrypted.</param> /// <param name="publicKeyAsByteArray">The public key used to encrypt the value.</param> public void Write(byte[] value, byte[] publicKeyAsByteArray) { using (Encryption.IPublicKey publicKey = Encryption.GetPublicKeyFromByteArray(publicKeyAsByteArray)) { Write(value, publicKey); } }
/// <summary> /// Creates an encrypted message /// </summary> /// <param name="recipientsPublicKey">The public portion of the message recpient's assymetric key.</param> /// <param name="plaintextMessageAsByteArray">The message to encrypt.</param> public EcEncryptedMessageAesCbcHmacSha256( byte[] plaintextMessageAsByteArray, Encryption.IPublicKey recipientsPublicKey = null) { PublicOneTimeEcKey = null; EncryptedMessage = plaintextMessageAsByteArray; //byte[] sessionKey; //using (CngKey oneTimeEcCngKey = CngKey.Create(CngAlgorithm.ECDiffieHellmanP256)) //{ // using (ECDiffieHellmanCng oneTimeEcKey = new ECDiffieHellmanCng(oneTimeEcCngKey)) // { // PublicOneTimeEcKey = oneTimeEcKey.PublicKey.ToByteArray(); // sessionKey = oneTimeEcKey.DeriveKeyMaterial(recipientsPublicKey); // } //} //EncryptedMessage = Encryption.EncryptAesCbc(plaintextMessageAsByteArray, sessionKey, addHmac: true); }
public void Write(T value, Encryption.IPublicKey publicKey) => Write(JsonConvert.SerializeObject(value), publicKey);
public void Write(string value, Encryption.IPublicKey publicKey) => Write(Encoding.UTF8.GetBytes(value), publicKey);
public void Write(byte[] value, Encryption.IPublicKey publicKey) { Ciphertext = JsonConvert.SerializeObject( new EcEncryptedMessageAesCbcHmacSha256(value, publicKey)); }
public EcEncryptedMessageAesCbcHmacSha256( byte[] plaintextMessageAsByteArray, Encryption.IPublicKey recipientsPublicKey = null) { PublicOneTimeEcKey = null; EncryptedMessage = plaintextMessageAsByteArray; }