Пример #1
0
 /// <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);
     }
 }
Пример #2
0
 /// <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);
 }
Пример #3
0
 public void Write(T value, Encryption.IPublicKey publicKey) =>
 Write(JsonConvert.SerializeObject(value), publicKey);
Пример #4
0
 public void Write(string value, Encryption.IPublicKey publicKey) =>
 Write(Encoding.UTF8.GetBytes(value), publicKey);
Пример #5
0
 public void Write(byte[] value, Encryption.IPublicKey publicKey)
 {
     Ciphertext = JsonConvert.SerializeObject(
         new EcEncryptedMessageAesCbcHmacSha256(value, publicKey));
 }
Пример #6
0
 public EcEncryptedMessageAesCbcHmacSha256(
     byte[] plaintextMessageAsByteArray, Encryption.IPublicKey recipientsPublicKey = null)
 {
     PublicOneTimeEcKey = null;
     EncryptedMessage   = plaintextMessageAsByteArray;
 }