Exemple #1
0
        public async Task <string> DecryptDataBlock(byte[] privateKey, EncryptedDataBlock dataBlock)
        {
            ValidateDigitalSignature(privateKey, dataBlock);

            return(await SymmetricallyDecrypt(Convert.FromBase64String(dataBlock.AesKey), Convert.FromBase64String(dataBlock.InitialisationVector),
                                              dataBlock.EncryptedData).ConfigureAwait(false));
        }
Exemple #2
0
        private static void ValidateDigitalSignature(byte[] privateKey, EncryptedDataBlock dataBlock)
        {
            try
            {
                var decryptedDigitalSignature = AsymmetricallyDecrypt(privateKey, dataBlock.DigitalSignature);
                var hash = GenerateHash(dataBlock.EncryptedData);

                if (string.Compare(decryptedDigitalSignature, hash, StringComparison.OrdinalIgnoreCase) != 0)
                {
                    throw new InvalidOperationException("The computed digital signature for the data block does not match the original digital signature.");
                }
            }
            catch (CryptographicException ex)
            {
                throw new InvalidOperationException("There was a problem decrypting the data block. Potential data corruption or packet tampering has occurred.", ex);
            }
        }