У меня есть
Код: Выделить всё
XMLDocumentКод: Выделить всё
SignedXmlКод: Выделить всё
AddAlgorithmКод: Выделить всё
CryptoConfig.AddAlgorithm(typeof(Ecdsa384SignatureDescription),
"http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha384");
Код: Выделить всё
AddAlgorithmКод: Выделить всё
SignedXmlКод: Выделить всё
CheckSignatureКод: Выделить всё
rsa-sha256After
Код: Выделить всё
AddAlgorithmКод: Выделить всё
InvalidOperationException
> There is an error in the XML document.
> was not expected.
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader)
Код: Выделить всё
...
This is the
Код: Выделить всё
Ecdsa384SignatureDescriptionКод: Выделить всё
SignatureDescription.csКод: Выделить всё
using System.Security.Cryptography;
public class ECDsaCngSignatureFormatter : AsymmetricSignatureFormatter
{
private ECDsaCng? key;
public ECDsaCngSignatureFormatter(ECDsaCng key)
{
this.key = key;
}
public override void SetKey(AsymmetricAlgorithm key) => this.key = key as ECDsaCng;
public override void SetHashAlgorithm(string strName) { }
public override byte[] CreateSignature(byte[] rgbHash) => key!.SignHash(rgbHash);
}
public class ECDsaCngSignatureDeformatter : AsymmetricSignatureDeformatter
{
private ECDsaCng? key;
public ECDsaCngSignatureDeformatter(ECDsaCng key)
{
this.key = key;
}
public override void SetKey(AsymmetricAlgorithm key) => this.key = key as ECDsaCng;
public override void SetHashAlgorithm(string strName) { }
public override bool VerifySignature(byte[] rgbHash, byte[] rgbSignature) => key!.VerifyHash(rgbHash, rgbSignature);
}
public class Ecdsa384SignatureDescription : SignatureDescription
{
public Ecdsa384SignatureDescription()
{
KeyAlgorithm = typeof(ECDsaCng).AssemblyQualifiedName;
}
public override HashAlgorithm CreateDigest() => SHA384.Create();
public override AsymmetricSignatureFormatter CreateFormatter(AsymmetricAlgorithm key)
{
if (!(key is ECDsaCng ecdsa) || ecdsa.KeySize != 384)
throw new InvalidOperationException("Requires EC key using P-256");
return new ECDsaCngSignatureFormatter(ecdsa);
}
public override AsymmetricSignatureDeformatter CreateDeformatter(AsymmetricAlgorithm key)
{
if (!(key is ECDsaCng ecdsa) || ecdsa.KeySize != 384)
throw new InvalidOperationException("Requires EC key using P-256");
return new ECDsaCngSignatureDeformatter(ecdsa);
}
}
Источник: https://stackoverflow.com/questions/781 ... -sharp-net
Мобильная версия