You've already forked linux-packaging-mono
Imported Upstream version 5.2.0.175
Former-commit-id: bb0468d0f257ff100aa895eb5fe583fb5dfbf900
This commit is contained in:
parent
4bdbaf4a88
commit
966bba02bb
@ -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)
|
||||
|
Reference in New Issue
Block a user