本文整理汇总了C#中AsymmetricAlgorithm类的典型用法代码示例。如果您正苦于以下问题:C# AsymmetricAlgorithm类的具体用法?C# AsymmetricAlgorithm怎么用?C# AsymmetricAlgorithm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AsymmetricAlgorithm类属于命名空间,在下文中一共展示了AsymmetricAlgorithm类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetHashAlgorithmEnum
/// <summary>
/// Gets the hash algorithm for a given asymmetric algorithm.
/// </summary>
/// <param name="algorithm">The algorithm.</param>
/// <returns>A hash algorithm.</returns>
internal static HashAlgorithm GetHashAlgorithmEnum(AsymmetricAlgorithm algorithm)
{
switch (algorithm)
{
case AsymmetricAlgorithm.DsaSha1:
case AsymmetricAlgorithm.RsaOaepSha1:
case AsymmetricAlgorithm.RsaSignPkcs1Sha1:
case AsymmetricAlgorithm.RsaSignPssSha1:
return HashAlgorithm.Sha1;
case AsymmetricAlgorithm.DsaSha256:
case AsymmetricAlgorithm.RsaOaepSha256:
case AsymmetricAlgorithm.EcdsaP256Sha256:
case AsymmetricAlgorithm.RsaSignPkcs1Sha256:
case AsymmetricAlgorithm.RsaSignPssSha256:
return HashAlgorithm.Sha256;
case AsymmetricAlgorithm.EcdsaP384Sha384:
case AsymmetricAlgorithm.RsaOaepSha384:
case AsymmetricAlgorithm.RsaSignPkcs1Sha384:
case AsymmetricAlgorithm.RsaSignPssSha384:
return HashAlgorithm.Sha384;
case AsymmetricAlgorithm.EcdsaP521Sha512:
case AsymmetricAlgorithm.RsaOaepSha512:
case AsymmetricAlgorithm.RsaSignPkcs1Sha512:
case AsymmetricAlgorithm.RsaSignPssSha512:
return HashAlgorithm.Sha512;
default:
throw new NotSupportedException();
}
}
示例2: SetKey
public override void SetKey(AsymmetricAlgorithm key)
{
if (key == null)
throw new ArgumentNullException(nameof(key));
_rsaKey = (RSA)key;
}
示例3: RSAOAEPKeyExchangeFormatter
public RSAOAEPKeyExchangeFormatter(AsymmetricAlgorithm key)
{
if (key == null)
throw new ArgumentNullException(nameof(key));
_rsaKey = (RSA)key;
}
示例4: OpenAlgorithm
/// <inheritdoc />
public IAsymmetricKeyAlgorithmProvider OpenAlgorithm(AsymmetricAlgorithm algorithm)
{
switch (algorithm)
{
#if DESKTOP
case AsymmetricAlgorithm.DsaSha1:
case AsymmetricAlgorithm.DsaSha256:
case AsymmetricAlgorithm.EcdsaP256Sha256:
case AsymmetricAlgorithm.EcdsaP384Sha384:
case AsymmetricAlgorithm.EcdsaP521Sha512:
return new CngAsymmetricKeyAlgorithmProvider(algorithm);
#endif
#if !SILVERLIGHT || WINDOWS_PHONE
case AsymmetricAlgorithm.RsaOaepSha1:
case AsymmetricAlgorithm.RsaOaepSha256:
case AsymmetricAlgorithm.RsaOaepSha384:
case AsymmetricAlgorithm.RsaOaepSha512:
case AsymmetricAlgorithm.RsaPkcs1:
case AsymmetricAlgorithm.RsaSignPkcs1Sha1:
case AsymmetricAlgorithm.RsaSignPkcs1Sha256:
case AsymmetricAlgorithm.RsaSignPkcs1Sha384:
case AsymmetricAlgorithm.RsaSignPkcs1Sha512:
case AsymmetricAlgorithm.RsaSignPssSha1:
case AsymmetricAlgorithm.RsaSignPssSha256:
case AsymmetricAlgorithm.RsaSignPssSha384:
case AsymmetricAlgorithm.RsaSignPssSha512:
return new RsaAsymmetricKeyAlgorithmProvider(algorithm);
#endif
default:
throw new NotSupportedException();
}
}
示例5: LegalKeySizes
public void LegalKeySizes(AsymmetricAlgorithm name, int minSize, int maxSize, int stepSize)
{
IAsymmetricKeyAlgorithmProvider provider = WinRTCrypto.AsymmetricKeyAlgorithmProvider.OpenAlgorithm(name);
var result = provider.LegalKeySizes;
Assert.NotNull(result);
Assert.NotEmpty(result);
Action<int> attemptKeySize = size =>
{
provider.CreateKeyPair(size).Dispose();
};
var range = result.Single();
Assert.Equal(minSize, range.MinSize);
Assert.Equal(maxSize, range.MaxSize);
Assert.Equal(stepSize, range.StepSize);
}
示例6: HttpConnection
public HttpConnection (Socket sock, EndPointListener epl, bool secure, X509Certificate2 cert, AsymmetricAlgorithm key)
{
this.sock = sock;
this.epl = epl;
this.secure = secure;
this.key = key;
if (secure == false) {
stream = new NetworkStream (sock, false);
} else {
SslServerStream ssl_stream = new SslServerStream (new NetworkStream (sock, false), cert, false, true, false);
ssl_stream.PrivateKeyCertSelectionDelegate += OnPVKSelection;
ssl_stream.ClientCertValidationDelegate += OnClientCertificateValidation;
stream = ssl_stream;
}
timer = new Timer (OnTimeout, null, Timeout.Infinite, Timeout.Infinite);
Init ();
}
示例7: AsymmetricEncryption
public void AsymmetricEncryption(AsymmetricAlgorithm algorithmName)
{
var algorithm = WinRTCrypto.AsymmetricKeyAlgorithmProvider.OpenAlgorithm(algorithmName);
foreach (var keySize in algorithm.LegalKeySizes.SelectMany(k => k))
{
try
{
this.logger.WriteLine($"Testing {algorithmName} with {keySize} bit key.");
using (var key = algorithm.CreateKeyPair(keySize))
{
}
break;
}
catch (ArgumentException)
{
// WinRT does not provide legal key sizes, and doesn't allow small RSA keys.
// It throws ArgumentException in this case. We can remove the skip on ArgumentException
// after we switch WinRT over to using BCrypt directly.
this.logger.WriteLine("Key size rejected. Please fix LegalKeySizes to report key sizes that actually work.");
}
}
}
示例8: SetKey
public abstract void SetKey(AsymmetricAlgorithm key);
示例9: RSAPKCS1KeyExchangeFormatter
public RSAPKCS1KeyExchangeFormatter(AsymmetricAlgorithm key)
{
}
示例10: AsymmetricKeyAlgorithmProvider
/// <summary>
/// Initializes a new instance of the <see cref="AsymmetricKeyAlgorithmProvider"/> class.
/// </summary>
/// <param name="algorithm">The algorithm.</param>
public AsymmetricKeyAlgorithmProvider(AsymmetricAlgorithm algorithm)
{
this.algorithm = algorithm;
this.platform = Platform.AsymmetricKeyAlgorithmProvider.OpenAlgorithm(GetAlgorithmName(algorithm));
}
示例11: SetKey
// Methods
public virtual void SetKey(AsymmetricAlgorithm key)
{
}
示例12: LogVerifySignedInfo
/// <summary>
/// Log the verification parameters when verifying the SignedInfo section of a signature using an
/// asymmetric key
/// </summary>
/// <param name="signedXml">SignedXml object doing the verification</param>
/// <param name="key">key being used to verify the signed info</param>
/// <param name="signatureDescription">type of signature description class used</param>
/// <param name="hashAlgorithm">type of hash algorithm used</param>
/// <param name="asymmetricSignatureDeformatter">type of signature deformatter used</param>
/// <param name="actualHashValue">hash value of the signed info</param>
/// <param name="signatureValue">raw signature value</param>
internal static void LogVerifySignedInfo(SignedXml signedXml,
AsymmetricAlgorithm key,
SignatureDescription signatureDescription,
HashAlgorithm hashAlgorithm,
AsymmetricSignatureDeformatter asymmetricSignatureDeformatter,
byte[] actualHashValue,
byte[] signatureValue) {
Debug.Assert(signedXml != null, "signedXml != null");
Debug.Assert(signatureDescription != null, "signatureDescription != null");
Debug.Assert(hashAlgorithm != null, "hashAlgorithm != null");
Debug.Assert(asymmetricSignatureDeformatter != null, "asymmetricSignatureDeformatter != null");
if (InformationLoggingEnabled) {
string logMessage = String.Format(CultureInfo.InvariantCulture,
SecurityResources.GetResourceString("Log_VerifySignedInfoAsymmetric"),
GetKeyName(key),
signatureDescription.GetType().Name,
hashAlgorithm.GetType().Name,
asymmetricSignatureDeformatter.GetType().Name);
WriteLine(signedXml,
TraceEventType.Information,
SignedXmlDebugEvent.VerifySignedInfo,
logMessage);
}
if (VerboseLoggingEnabled) {
string hashLog = String.Format(CultureInfo.InvariantCulture,
SecurityResources.GetResourceString("Log_ActualHashValue"),
FormatBytes(actualHashValue));
WriteLine(signedXml, TraceEventType.Verbose, SignedXmlDebugEvent.VerifySignedInfo, hashLog);
string signatureLog = String.Format(CultureInfo.InvariantCulture,
SecurityResources.GetResourceString("Log_RawSignatureValue"),
FormatBytes(signatureValue));
WriteLine(signedXml, TraceEventType.Verbose, SignedXmlDebugEvent.VerifySignedInfo, signatureLog);
}
}
示例13: CreateFormatter
public override AsymmetricSignatureFormatter CreateFormatter(AsymmetricAlgorithm key)
{
if (key == null)
{
throw new ArgumentNullException("key");
}
RSAPKCS1SignatureFormatter formatter = new RSAPKCS1SignatureFormatter(key);
formatter.SetHashAlgorithm("SHA256");
return formatter;
}
示例14: DSASignatureDeformatter
public DSASignatureDeformatter(AsymmetricAlgorithm key) {}
示例15: PublicKey
internal PublicKey (Mono.Security.X509.X509Certificate certificate)
{
if (certificate.KeyAlgorithm == "1.2.840.113549.1.1.1") {
_key = certificate.RSA;
}
else {
_key = certificate.DSA;
}
_oid = new Oid (certificate.KeyAlgorithm);
_keyValue = new AsnEncodedData (_oid, certificate.PublicKey);
_params = new AsnEncodedData (_oid, certificate.KeyAlgorithmParameters);
}