Files
Dec2017-Script-Dump/mscorlib/System/Security/Cryptography/RSAPKCS1SignatureFormatter.cs
T
2026-06-04 11:42:34 +02:00

83 lines
3.5 KiB
C#

using System;
using System.Runtime.InteropServices;
using Mono.Security.Cryptography;
namespace System.Security.Cryptography
{
/// <summary>Creates an <see cref="T:System.Security.Cryptography.RSA" /> PKCS #1 version 1.5 signature.</summary>
// Token: 0x02000522 RID: 1314
[ComVisible(true)]
public class RSAPKCS1SignatureFormatter : AsymmetricSignatureFormatter
{
/// <summary>Initializes a new instance of the <see cref="T:System.Security.Cryptography.RSAPKCS1SignatureFormatter" /> class.</summary>
// Token: 0x06003056 RID: 12374 RVA: 0x0009E044 File Offset: 0x0009C244
public RSAPKCS1SignatureFormatter()
{
}
/// <summary>Initializes a new instance of the <see cref="T:System.Security.Cryptography.RSAPKCS1SignatureFormatter" /> class with the specified key.</summary>
/// <param name="key">The instance of the <see cref="T:System.Security.Cryptography.RSA" /> algorithm that holds the private key. </param>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="key" /> is null.</exception>
// Token: 0x06003057 RID: 12375 RVA: 0x0009E04C File Offset: 0x0009C24C
public RSAPKCS1SignatureFormatter(AsymmetricAlgorithm key)
{
this.SetKey(key);
}
/// <summary>Creates the <see cref="T:System.Security.Cryptography.RSA" /> PKCS #1 signature for the specified data.</summary>
/// <returns>The digital signature for <paramref name="rgbHash" />.</returns>
/// <param name="rgbHash">The data to be signed. </param>
/// <exception cref="T:System.Security.Cryptography.CryptographicUnexpectedOperationException">The key is null.-or- The hash algorithm is null. </exception>
/// <exception cref="T:System.ArgumentNullException">The <paramref name="rgbHash" /> parameter is null. </exception>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.KeyContainerPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
/// </PermissionSet>
// Token: 0x06003058 RID: 12376 RVA: 0x0009E05C File Offset: 0x0009C25C
public override byte[] CreateSignature(byte[] rgbHash)
{
if (this.rsa == null)
{
throw new CryptographicUnexpectedOperationException(Locale.GetText("No key pair available."));
}
if (this.hash == null)
{
throw new CryptographicUnexpectedOperationException(Locale.GetText("Missing hash algorithm."));
}
if (rgbHash == null)
{
throw new ArgumentNullException("rgbHash");
}
return PKCS1.Sign_v15(this.rsa, this.hash, rgbHash);
}
/// <summary>Sets the hash algorithm to use for creating the signature.</summary>
/// <param name="strName">The name of the hash algorithm to use for creating the signature. </param>
// Token: 0x06003059 RID: 12377 RVA: 0x0009E0C4 File Offset: 0x0009C2C4
public override void SetHashAlgorithm(string strName)
{
this.hash = HashAlgorithm.Create(strName);
}
/// <summary>Sets the private key to use for creating the signature.</summary>
/// <param name="key">The instance of the <see cref="T:System.Security.Cryptography.RSA" /> algorithm that holds the private key. </param>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="key" /> is null.</exception>
// Token: 0x0600305A RID: 12378 RVA: 0x0009E0D4 File Offset: 0x0009C2D4
public override void SetKey(AsymmetricAlgorithm key)
{
if (key == null)
{
throw new ArgumentNullException("key");
}
this.rsa = (RSA)key;
}
// Token: 0x040013A5 RID: 5029
private RSA rsa;
// Token: 0x040013A6 RID: 5030
private HashAlgorithm hash;
}
}