public void GetDecryptionIV_TripleDesUri() { EncryptedXml ex = new EncryptedXml(); EncryptedData encryptedData = new EncryptedData(); encryptedData.CipherData = new CipherData(new byte[16]); Assert.Equal(8, ex.GetDecryptionIV(encryptedData, EncryptedXml.XmlEncTripleDESUrl).Length); }
public void GetDecryptionIV_StringNullWithoutEncryptionMethod() { EncryptedXml ex = new EncryptedXml(); EncryptedData encryptedData = new EncryptedData(); encryptedData.CipherData = new CipherData(new byte[16]); Assert.Throws <CryptographicException>(() => ex.GetDecryptionIV(encryptedData, null)); }
public void GetDecryptionIV_InvalidAlgorithmUri() { EncryptedXml ex = new EncryptedXml(); EncryptedData encryptedData = new EncryptedData(); encryptedData.CipherData = new CipherData(new byte[16]); Assert.Throws <CryptographicException>(() => ex.GetDecryptionIV(encryptedData, "invalid")); }
public void GetDecryptionIV_StringNull() { EncryptedXml ex = new EncryptedXml(); EncryptedData encryptedData = new EncryptedData(); encryptedData.EncryptionMethod = new EncryptionMethod(EncryptedXml.XmlEncAES256Url); encryptedData.CipherData = new CipherData(new byte[16]); Assert.Equal(new byte[16], ex.GetDecryptionIV(encryptedData, null)); }
public void GetDecryptionIV_StringNull() { // Added EncryptionMethod and CipherData to avoid a CryptographicException EncryptedXml ex = new EncryptedXml(); EncryptedData encryptedData = new EncryptedData(); encryptedData.EncryptionMethod = new EncryptionMethod(EncryptedXml.XmlEncAES256Url); encryptedData.CipherData = new CipherData(new byte[16]); Assert.Null(ex.GetDecryptionIV(encryptedData, null)); }
public void GetDecryptionIV_StringNull() { EncryptedXml ex = new EncryptedXml(); Assert.IsNull(ex.GetDecryptionIV(new EncryptedData(), null)); }
public void GetDecryptionIV_EncryptedDataNull() { EncryptedXml ex = new EncryptedXml(); ex.GetDecryptionIV(null, EncryptedXml.XmlEncAES128Url); }
public void GetDecryptionIV_EncryptedDataNull() { EncryptedXml ex = new EncryptedXml(); Assert.Throws <ArgumentNullException>(() => ex.GetDecryptionIV(null, EncryptedXml.XmlEncAES128Url)); }
private bool TryDecrypt(EncryptedType encryptedType, out byte[] plainText) { var xml = new EncryptedXml(); var keys = GetSecurityKeys(encryptedType); var algorithm = encryptedType.EncryptionMethod.KeyAlgorithm; foreach (var key in keys) { var crypto = GetCrypto(key); if (!crypto.IsSupportedAlgorithm(algorithm, key)) { continue; } var symmetric = null as SymmetricAlgorithm; try { if (encryptedType is EncryptedData encryptedData) { if (!(key is SymmetricSecurityKey symmetricKey)) { continue; } symmetric = crypto.CreateSymmetricAlgorithm(symmetricKey, algorithm); symmetric.IV = xml.GetDecryptionIV(encryptedData, algorithm); var pt = xml.DecryptData(encryptedData, symmetric); plainText = pt; return(true); } if (encryptedType is EncryptedKey encryptedKey) { var pt = null as byte[]; var keyWrapAlgorithm = encryptedKey.EncryptionMethod.KeyAlgorithm; if (crypto.IsSupportedAlgorithm(algorithm, key)) { var keyWrap = crypto.CreateKeyWrapProviderForUnwrap(key, encryptedKey.EncryptionMethod.KeyAlgorithm); try { pt = keyWrap.UnwrapKey(encryptedKey.CipherData.CipherValue); plainText = pt; return(true); } finally { crypto.ReleaseKeyWrapProvider(keyWrap); } } } } catch (Exception ex) { } finally { if (symmetric != null) { crypto.ReleaseSymmetricAlgorithm(symmetric); symmetric = null; } } } return(Out.False(out plainText)); }