Imported Upstream version 5.2.0.175

Former-commit-id: bb0468d0f257ff100aa895eb5fe583fb5dfbf900
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2017-06-07 13:16:24 +00:00
parent 4bdbaf4a88
commit 966bba02bb
8776 changed files with 346420 additions and 149650 deletions

View File

@ -46,8 +46,8 @@ namespace System.Security.Cryptography.Xml {
{
}
public CipherReference (string uri, TransformChain tc)
: base (uri, tc)
public CipherReference (string uri, TransformChain transformChain)
: base (uri, transformChain)
{
}

View File

@ -48,8 +48,8 @@ namespace System.Security.Cryptography.Xml {
ReferenceType = XmlEncryption.ElementNames.DataReference;
}
public DataReference (string uri, TransformChain tc)
: base (uri, tc)
public DataReference (string uri, TransformChain transformChain)
: base (uri, transformChain)
{
ReferenceType = XmlEncryption.ElementNames.DataReference;
}

View File

@ -55,11 +55,11 @@ namespace System.Security.Cryptography.Xml {
TransformChain = new TransformChain ();
}
protected EncryptedReference (string uri, TransformChain tc)
protected EncryptedReference (string uri, TransformChain transformChain)
: this ()
{
Uri = uri;
TransformChain = tc;
TransformChain = transformChain;
}
#endregion // Constructors

View File

@ -138,19 +138,19 @@ namespace System.Security.Cryptography.Xml {
keyNameMapping.Clear ();
}
public byte[] DecryptData (EncryptedData encryptedData, SymmetricAlgorithm symAlg)
public byte[] DecryptData (EncryptedData encryptedData, SymmetricAlgorithm symmetricAlgorithm)
{
if (encryptedData == null)
throw new ArgumentNullException ("encryptedData");
if (symAlg == null)
throw new ArgumentNullException ("symAlg");
if (symmetricAlgorithm == null)
throw new ArgumentNullException ("symmetricAlgorithm");
PaddingMode bak = symAlg.Padding;
PaddingMode bak = symmetricAlgorithm.Padding;
try {
symAlg.Padding = Padding;
return Transform (encryptedData.CipherData.CipherValue, symAlg.CreateDecryptor (), symAlg.BlockSize / 8, true);
symmetricAlgorithm.Padding = Padding;
return Transform (encryptedData.CipherData.CipherValue, symmetricAlgorithm.CreateDecryptor (), symmetricAlgorithm.BlockSize / 8, true);
} finally {
symAlg.Padding = bak;
symmetricAlgorithm.Padding = bak;
}
}
@ -186,25 +186,25 @@ namespace System.Security.Cryptography.Xml {
return DecryptKey (encryptedKey.CipherData.CipherValue, (SymmetricAlgorithm) keyAlg);
}
public static byte[] DecryptKey (byte[] keyData, SymmetricAlgorithm symAlg)
public static byte[] DecryptKey (byte[] keyData, SymmetricAlgorithm symmetricAlgorithm)
{
if (keyData == null)
throw new ArgumentNullException ("keyData");
if (symAlg == null)
throw new ArgumentNullException ("symAlg");
if (symmetricAlgorithm == null)
throw new ArgumentNullException ("symmetricAlgorithm");
if (symAlg is TripleDES)
return SymmetricKeyWrap.TripleDESKeyWrapDecrypt (symAlg.Key, keyData);
if (symAlg is Rijndael)
return SymmetricKeyWrap.AESKeyWrapDecrypt (symAlg.Key, keyData);
if (symmetricAlgorithm is TripleDES)
return SymmetricKeyWrap.TripleDESKeyWrapDecrypt (symmetricAlgorithm.Key, keyData);
if (symmetricAlgorithm is Rijndael)
return SymmetricKeyWrap.AESKeyWrapDecrypt (symmetricAlgorithm.Key, keyData);
throw new CryptographicException ("The specified cryptographic transform is not supported.");
}
[MonoTODO ("Test this.")]
public static byte[] DecryptKey (byte[] keyData, RSA rsa, bool fOAEP)
public static byte[] DecryptKey (byte[] keyData, RSA rsa, bool useOAEP)
{
AsymmetricKeyExchangeDeformatter deformatter = null;
if (fOAEP)
if (useOAEP)
deformatter = new RSAOAEPKeyExchangeDeformatter (rsa);
else
deformatter = new RSAPKCS1KeyExchangeDeformatter (rsa);
@ -254,19 +254,19 @@ namespace System.Security.Cryptography.Xml {
throw new NotImplementedException ();
}
public byte[] EncryptData (byte[] plainText, SymmetricAlgorithm symAlg)
public byte[] EncryptData (byte[] plaintext, SymmetricAlgorithm symmetricAlgorithm)
{
if (plainText == null)
throw new ArgumentNullException ("plainText");
if (symAlg == null)
throw new ArgumentNullException ("symAlg");
if (plaintext == null)
throw new ArgumentNullException ("plaintext");
if (symmetricAlgorithm == null)
throw new ArgumentNullException ("symmetricAlgorithm");
PaddingMode bak = symAlg.Padding;
PaddingMode bak = symmetricAlgorithm.Padding;
try {
symAlg.Padding = Padding;
return EncryptDataCore (plainText, symAlg);
symmetricAlgorithm.Padding = Padding;
return EncryptDataCore (plaintext, symmetricAlgorithm);
} finally {
symAlg.Padding = bak;
symmetricAlgorithm.Padding = bak;
}
}
@ -289,37 +289,37 @@ namespace System.Security.Cryptography.Xml {
return output;
}
public byte[] EncryptData (XmlElement inputElement, SymmetricAlgorithm symAlg, bool content)
public byte[] EncryptData (XmlElement inputElement, SymmetricAlgorithm symmetricAlgorithm, bool content)
{
if (inputElement == null)
throw new ArgumentNullException ("inputElement");
if (content)
return EncryptData (Encoding.GetBytes (inputElement.InnerXml), symAlg);
return EncryptData (Encoding.GetBytes (inputElement.InnerXml), symmetricAlgorithm);
else
return EncryptData (Encoding.GetBytes (inputElement.OuterXml), symAlg);
return EncryptData (Encoding.GetBytes (inputElement.OuterXml), symmetricAlgorithm);
}
public static byte[] EncryptKey (byte[] keyData, SymmetricAlgorithm symAlg)
public static byte[] EncryptKey (byte[] keyData, SymmetricAlgorithm symmetricAlgorithm)
{
if (keyData == null)
throw new ArgumentNullException ("keyData");
if (symAlg == null)
throw new ArgumentNullException ("symAlg");
if (symmetricAlgorithm == null)
throw new ArgumentNullException ("symmetricAlgorithm");
if (symAlg is TripleDES)
return SymmetricKeyWrap.TripleDESKeyWrapEncrypt (symAlg.Key, keyData);
if (symAlg is Rijndael)
return SymmetricKeyWrap.AESKeyWrapEncrypt (symAlg.Key, keyData);
if (symmetricAlgorithm is TripleDES)
return SymmetricKeyWrap.TripleDESKeyWrapEncrypt (symmetricAlgorithm.Key, keyData);
if (symmetricAlgorithm is Rijndael)
return SymmetricKeyWrap.AESKeyWrapEncrypt (symmetricAlgorithm.Key, keyData);
throw new CryptographicException ("The specified cryptographic transform is not supported.");
}
[MonoTODO ("Test this.")]
public static byte[] EncryptKey (byte[] keyData, RSA rsa, bool fOAEP)
public static byte[] EncryptKey (byte[] keyData, RSA rsa, bool useOAEP)
{
AsymmetricKeyExchangeFormatter formatter = null;
if (fOAEP)
if (useOAEP)
formatter = new RSAOAEPKeyExchangeFormatter (rsa);
else
formatter = new RSAPKCS1KeyExchangeFormatter (rsa);
@ -402,25 +402,25 @@ namespace System.Security.Cryptography.Xml {
throw new ArgumentException ("keyAlg");
}
public virtual byte[] GetDecryptionIV (EncryptedData encryptedData, string symAlgUri)
public virtual byte[] GetDecryptionIV (EncryptedData encryptedData, string symmetricAlgorithmUri)
{
if (encryptedData == null)
throw new ArgumentNullException ("encryptedData");
SymmetricAlgorithm symAlg = GetAlgorithm (symAlgUri);
SymmetricAlgorithm symAlg = GetAlgorithm (symmetricAlgorithmUri);
byte[] iv = new Byte [symAlg.BlockSize / 8];
Buffer.BlockCopy (encryptedData.CipherData.CipherValue, 0, iv, 0, iv.Length);
return iv;
}
public virtual SymmetricAlgorithm GetDecryptionKey (EncryptedData encryptedData, string symAlgUri)
public virtual SymmetricAlgorithm GetDecryptionKey (EncryptedData encryptedData, string symmetricAlgorithmUri)
{
if (encryptedData == null)
throw new ArgumentNullException ("encryptedData");
if (symAlgUri == null)
if (symmetricAlgorithmUri == null)
return null;
SymmetricAlgorithm symAlg = GetAlgorithm (symAlgUri);
SymmetricAlgorithm symAlg = GetAlgorithm (symmetricAlgorithmUri);
symAlg.IV = GetDecryptionIV (encryptedData, encryptedData.EncryptionMethod.KeyAlgorithm);
KeyInfo keyInfo = encryptedData.KeyInfo;
foreach (KeyInfoClause clause in keyInfo) {

View File

@ -48,9 +48,9 @@ namespace System.Security.Cryptography.Xml {
KeyAlgorithm = null;
}
public EncryptionMethod (string strAlgorithm)
public EncryptionMethod (string algorithm)
{
KeyAlgorithm = strAlgorithm;
KeyAlgorithm = algorithm;
}
#endregion // Constructors

View File

@ -47,9 +47,9 @@ namespace System.Security.Cryptography.Xml {
{
}
public EncryptionProperty (XmlElement elemProp)
public EncryptionProperty (XmlElement elementProperty)
{
LoadXml (elemProp);
LoadXml (elementProperty);
}
#endregion // Constructors

View File

@ -48,9 +48,9 @@ namespace System.Security.Cryptography.Xml {
{
}
public KeyInfoEncryptedKey (EncryptedKey ek)
public KeyInfoEncryptedKey (EncryptedKey encryptedKey)
{
EncryptedKey = ek;
EncryptedKey = encryptedKey;
}
#endregion // Constructors

View File

@ -49,10 +49,10 @@ namespace System.Security.Cryptography.Xml {
URI = strUri;
}
public KeyInfoRetrievalMethod (string strUri, string strType)
public KeyInfoRetrievalMethod (string strUri, string typeName)
: this (strUri)
{
Type = strType;
Type = typeName;
}
[ComVisible (false)]

View File

@ -48,8 +48,8 @@ namespace System.Security.Cryptography.Xml {
ReferenceType = XmlEncryption.ElementNames.KeyReference;
}
public KeyReference (string uri, TransformChain tc)
: base (uri, tc)
public KeyReference (string uri, TransformChain transformChain)
: base (uri, transformChain)
{
ReferenceType = XmlEncryption.ElementNames.KeyReference;
}

View File

@ -624,34 +624,36 @@ namespace System.Security.Cryptography.Xml {
public void ComputeSignature ()
{
if (key != null) {
if (m_signature.SignedInfo.SignatureMethod == null)
// required before hashing
m_signature.SignedInfo.SignatureMethod = key.SignatureAlgorithm;
else if (m_signature.SignedInfo.SignatureMethod != key.SignatureAlgorithm)
throw new CryptographicException ("Specified SignatureAlgorithm is not supported by the signing key.");
DigestReferences ();
DigestReferences ();
AsymmetricSignatureFormatter signer = null;
// in need for a CryptoConfig factory
if (key is DSA)
signer = new DSASignatureFormatter (key);
else if (key is RSA)
signer = new RSAPKCS1SignatureFormatter (key);
if (key == null)
throw new CryptographicException (SR.Cryptography_Xml_LoadKeyFailed);
if (signer != null) {
SignatureDescription sd = (SignatureDescription) CryptoConfig.CreateFromName (m_signature.SignedInfo.SignatureMethod);
HashAlgorithm hash = GetHash (sd.DigestAlgorithm, false);
// get the hash of the C14N SignedInfo element
byte[] digest = hash.ComputeHash (SignedInfoTransformed ());
signer.SetHashAlgorithm ("SHA1");
m_signature.SignatureValue = signer.CreateSignature (digest);
// Check the signature algorithm associated with the key so that we can accordingly set the signature method
if (SignedInfo.SignatureMethod == null) {
if (key is DSA) {
SignedInfo.SignatureMethod = XmlDsigDSAUrl;
} else if (key is RSA) {
// Default to RSA-SHA1
SignedInfo.SignatureMethod = XmlDsigRSASHA1Url;
} else {
throw new CryptographicException (SR.Cryptography_Xml_CreatedKeyFailed);
}
}
else
throw new CryptographicException ("signing key is not specified");
// See if there is a signature description class defined in the Config file
SignatureDescription signatureDescription = CryptoConfig.CreateFromName (SignedInfo.SignatureMethod) as SignatureDescription;
if (signatureDescription == null)
throw new CryptographicException (SR.Cryptography_Xml_SignatureDescriptionNotCreated);
HashAlgorithm hashAlg = signatureDescription.CreateDigest ();
if (hashAlg == null)
throw new CryptographicException (SR.Cryptography_Xml_CreateHashAlgorithmFailed);
byte[] hashvalue = hashAlg.ComputeHash (SignedInfoTransformed ());
AsymmetricSignatureFormatter asymmetricSignatureFormatter = signatureDescription.CreateFormatter (key);
m_signature.SignatureValue = asymmetricSignatureFormatter.CreateSignature (hashAlg);
}
public void ComputeSignature (KeyedHashAlgorithm macAlg)