3 // Copyright (c) Microsoft Corporation. All rights reserved.
6 // <OWNER>Microsoft</OWNER>
10 // DSASignatureFormatter.cs
14 using System.Diagnostics.Contracts;
15 using System.Security.Cryptography.X509Certificates;
17 namespace System.Security.Cryptography {
18 [System.Runtime.InteropServices.ComVisible(true)]
19 public class DSASignatureFormatter : AsymmetricSignatureFormatter {
24 // public constructors
27 public DSASignatureFormatter() {
28 // The hash algorithm is always SHA1
29 _oid = CryptoConfig.MapNameToOID("SHA1", OidGroup.HashAlgorithm);
32 public DSASignatureFormatter(AsymmetricAlgorithm key) : this() {
34 throw new ArgumentNullException("key");
35 Contract.EndContractBlock();
43 public override void SetKey(AsymmetricAlgorithm key) {
45 throw new ArgumentNullException("key");
46 Contract.EndContractBlock();
50 public override void SetHashAlgorithm(String strName) {
51 if (CryptoConfig.MapNameToOID(strName, OidGroup.HashAlgorithm) != _oid)
52 throw new CryptographicUnexpectedOperationException(Environment.GetResourceString("Cryptography_InvalidOperation"));
55 public override byte[] CreateSignature(byte[] rgbHash) {
57 throw new ArgumentNullException("rgbHash");
58 Contract.EndContractBlock();
61 throw new CryptographicUnexpectedOperationException(Environment.GetResourceString("Cryptography_MissingOID"));
63 throw new CryptographicUnexpectedOperationException(Environment.GetResourceString("Cryptography_MissingKey"));
65 return _dsaKey.CreateSignature(rgbHash);