• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# AsymmetricAlgorithm类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中AsymmetricAlgorithm的典型用法代码示例。如果您正苦于以下问题:C# AsymmetricAlgorithm类的具体用法?C# AsymmetricAlgorithm怎么用?C# AsymmetricAlgorithm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



AsymmetricAlgorithm类属于命名空间,在下文中一共展示了AsymmetricAlgorithm类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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();
     }
 }
开发者ID:martijn00,项目名称:PCLCrypto,代码行数:34,代码来源:AsymmetricKeyAlgorithmProviderFactory.cs


示例2: SetKey

        public override void SetKey(AsymmetricAlgorithm key)
        {
            if (key == null)
                throw new ArgumentNullException(nameof(key));

            _rsaKey = (RSA)key;
        }
开发者ID:dotnet,项目名称:corefx,代码行数:7,代码来源:RSAOAEPKeyExchangeFormatter.cs


示例3: RSAOAEPKeyExchangeFormatter

        public RSAOAEPKeyExchangeFormatter(AsymmetricAlgorithm key)
        {
            if (key == null)
                throw new ArgumentNullException(nameof(key));

            _rsaKey = (RSA)key;
        }
开发者ID:dotnet,项目名称:corefx,代码行数:7,代码来源:RSAOAEPKeyExchangeFormatter.cs


示例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();
            }
        }
开发者ID:martijn00,项目名称:PCLCrypto,代码行数:33,代码来源:AsymmetricKeyAlgorithmProviderFactory.cs


示例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);
    }
开发者ID:martijn00,项目名称:PCLCrypto,代码行数:17,代码来源:AsymmetricKeyAlgorithmProviderTests.cs


示例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 ();
		}
开发者ID:GirlD,项目名称:mono,代码行数:17,代码来源:HttpConnection.cs


示例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.");
            }
        }
    }
开发者ID:martijn00,项目名称:PCLCrypto,代码行数:24,代码来源:PlatformSupport.cs


示例8: SetKey

 public abstract void SetKey(AsymmetricAlgorithm key);
开发者ID:geoffkizer,项目名称:corefx,代码行数:1,代码来源:AsymmetricKeyExchangeDeformatter.cs


示例9: RSAPKCS1KeyExchangeFormatter

 public RSAPKCS1KeyExchangeFormatter(AsymmetricAlgorithm key)
 {
 }
开发者ID:Pengfei-Gao,项目名称:source-Insight-3-for-centos7,代码行数:3,代码来源:RSAPKCS1KeyExchangeFormatter.cs


示例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));
 }
开发者ID:gitter-badger,项目名称:PCLCrypto,代码行数:9,代码来源:AsymmetricKeyAlgorithmProvider.cs


示例11: SetKey

 // Methods
 public virtual void SetKey(AsymmetricAlgorithm key)
 {
 }
开发者ID:Pengfei-Gao,项目名称:source-Insight-3-for-centos7,代码行数:4,代码来源:RSAPKCS1SignatureDeformatter.cs


示例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);
            }
        }
开发者ID:mind0n,项目名称:hive,代码行数:48,代码来源:SignedXmlDebugLog.cs


示例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;
        }
开发者ID:Mahendrasiddappa,项目名称:Binary_server,代码行数:11,代码来源:program-repro-misc-validation-and-canon.cs


示例14: DSASignatureDeformatter

	public DSASignatureDeformatter(AsymmetricAlgorithm key) {}
开发者ID:Pengfei-Gao,项目名称:source-Insight-3-for-centos7,代码行数:1,代码来源:DSASignatureDeformatter.cs


示例15: VerifySignatureWithTolerantHashAlgorithm

        /// <summary>
        /// Verifies the asymmetric signature of some data blob.
        /// </summary>
        /// <param name="signingPublicKey">The public key used to verify the signature.</param>
        /// <param name="data">The data that was signed.</param>
        /// <param name="signature">The signature.</param>
        /// <param name="signingAlgorithm">The signing algorithm.</param>
        /// <returns>
        /// A value indicating whether the signature is valid.
        /// </returns>
        internal static bool VerifySignatureWithTolerantHashAlgorithm(byte[] signingPublicKey, byte[] data, byte[] signature, AsymmetricAlgorithm? signingAlgorithm = null)
        {
            if (signingAlgorithm.HasValue)
            {
                var key = WinRTCrypto.AsymmetricKeyAlgorithmProvider.OpenAlgorithm(signingAlgorithm.Value)
                    .ImportPublicKey(signingPublicKey, CryptoSettings.PublicKeyFormat);
                return WinRTCrypto.CryptographicEngine.VerifySignature(key, data, signature);
            }

            var key1 = WinRTCrypto.AsymmetricKeyAlgorithmProvider.OpenAlgorithm(AsymmetricAlgorithm.RsaSignPkcs1Sha1)
                .ImportPublicKey(signingPublicKey, CryptoSettings.PublicKeyFormat);
            var key2 = WinRTCrypto.AsymmetricKeyAlgorithmProvider.OpenAlgorithm(AsymmetricAlgorithm.RsaSignPkcs1Sha256)
                .ImportPublicKey(signingPublicKey, CryptoSettings.PublicKeyFormat);
            return WinRTCrypto.CryptographicEngine.VerifySignature(key1, data, signature)
                || WinRTCrypto.CryptographicEngine.VerifySignature(key2, data, signature);
        }
开发者ID:AArnott,项目名称:IronPigeon,代码行数:26,代码来源:CryptoProviderExtensions.cs


示例16: SetKey

	// Methods
	public abstract virtual void SetKey(AsymmetricAlgorithm key) {}
开发者ID:Pengfei-Gao,项目名称:source-Insight-3-for-centos7,代码行数:2,代码来源:AsymmetricSignatureDeformatter.cs


示例17: CalculateSignerPublicKeyToken

        private static byte[] CalculateSignerPublicKeyToken(AsymmetricAlgorithm key) {
            Debug.Assert(key != null, "key != null");

            ICspAsymmetricAlgorithm cspAlgorithm = key as ICspAsymmetricAlgorithm;
            if (cspAlgorithm == null) {
                return null;
            }

            byte[] publicKey = cspAlgorithm.ExportCspBlob(false);
            SafeAxlBufferHandle tokenBuffer;

            unsafe {
                fixed (byte* pPublicKey = publicKey) {
                    // Safe, since we're ensuring the CAPI buffer going in is sized correctly
                    CapiNative.CRYPTOAPI_BLOB keyBlob = new CapiNative.CRYPTOAPI_BLOB();
                    keyBlob.cbData = publicKey.Length;
                    keyBlob.pbData = new IntPtr(pPublicKey);

                    int hrToken = CapiNative.UnsafeNativeMethods._AxlPublicKeyBlobToPublicKeyToken(ref keyBlob,
                                                                                                   out tokenBuffer);
                    if (((uint)hrToken & 0x80000000) != 0) {
                        return null;
                    }
                }
            }

            bool acquired = false;

            RuntimeHelpers.PrepareConstrainedRegions();
            try {
                tokenBuffer.DangerousAddRef(ref acquired);
                return HexStringToBytes(Marshal.PtrToStringUni(tokenBuffer.DangerousGetHandle()));
            }
            finally {
                if (acquired) {
                    tokenBuffer.DangerousRelease();
                }
            }
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:39,代码来源:ManifestSignedXml.cs


示例18: RSAPKCS1SignatureDeformatter

 public RSAPKCS1SignatureDeformatter(AsymmetricAlgorithm key)
 {
 }
开发者ID:Pengfei-Gao,项目名称:source-Insight-3-for-centos7,代码行数:3,代码来源:RSAPKCS1SignatureDeformatter.cs


示例19: RSAOAEPKeyExchangeDeformatter

 public RSAOAEPKeyExchangeDeformatter(AsymmetricAlgorithm key)
 {
 }
开发者ID:Pengfei-Gao,项目名称:source-Insight-3-for-centos7,代码行数:3,代码来源:RSAOAEPKeyExchangeDeformatter.cs


示例20: GetAlgorithmName

 /// <summary>
 /// Returns the string to pass to the platform APIs for a given algorithm.
 /// </summary>
 /// <param name="algorithm">The algorithm desired.</param>
 /// <returns>The platform-specific string to pass to OpenAlgorithm.</returns>
 private static string GetAlgorithmName(AsymmetricAlgorithm algorithm)
 {
     switch (algorithm)
     {
         case AsymmetricAlgorithm.DsaSha1:
             return Platform.AsymmetricAlgorithmNames.DsaSha1;
         case AsymmetricAlgorithm.DsaSha256:
             return Platform.AsymmetricAlgorithmNames.DsaSha256;
         case AsymmetricAlgorithm.EcdsaP256Sha256:
             return Platform.AsymmetricAlgorithmNames.EcdsaP256Sha256;
         case AsymmetricAlgorithm.EcdsaP384Sha384:
             return Platform.AsymmetricAlgorithmNames.EcdsaP384Sha384;
         case AsymmetricAlgorithm.EcdsaP521Sha512:
             return Platform.AsymmetricAlgorithmNames.EcdsaP521Sha512;
         case AsymmetricAlgorithm.RsaOaepSha1:
             return Platform.AsymmetricAlgorithmNames.RsaOaepSha1;
         case AsymmetricAlgorithm.RsaOaepSha256:
             return Platform.AsymmetricAlgorithmNames.RsaOaepSha256;
         case AsymmetricAlgorithm.RsaOaepSha384:
             return Platform.AsymmetricAlgorithmNames.RsaOaepSha384;
         case AsymmetricAlgorithm.RsaOaepSha512:
             return Platform.AsymmetricAlgorithmNames.RsaOaepSha512;
         case AsymmetricAlgorithm.RsaPkcs1:
             return Platform.AsymmetricAlgorithmNames.RsaPkcs1;
         case AsymmetricAlgorithm.RsaSignPkcs1Sha1:
             return Platform.AsymmetricAlgorithmNames.RsaSignPkcs1Sha1;
         case AsymmetricAlgorithm.RsaSignPkcs1Sha256:
             return Platform.AsymmetricAlgorithmNames.RsaSignPkcs1Sha256;
         case AsymmetricAlgorithm.RsaSignPkcs1Sha384:
             return Platform.AsymmetricAlgorithmNames.RsaSignPkcs1Sha384;
         case AsymmetricAlgorithm.RsaSignPkcs1Sha512:
             return Platform.AsymmetricAlgorithmNames.RsaSignPkcs1Sha512;
         case AsymmetricAlgorithm.RsaSignPssSha1:
             return Platform.AsymmetricAlgorithmNames.RsaSignPssSha1;
         case AsymmetricAlgorithm.RsaSignPssSha256:
             return Platform.AsymmetricAlgorithmNames.RsaSignPssSha256;
         case AsymmetricAlgorithm.RsaSignPssSha384:
             return Platform.AsymmetricAlgorithmNames.RsaSignPssSha384;
         case AsymmetricAlgorithm.RsaSignPssSha512:
             return Platform.AsymmetricAlgorithmNames.RsaSignPssSha512;
         default:
             throw new NotSupportedException();
     }
 }
开发者ID:gitter-badger,项目名称:PCLCrypto,代码行数:49,代码来源:AsymmetricKeyAlgorithmProvider.cs



注:本文中的AsymmetricAlgorithm类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# AsymmetricKeyParameter类代码示例发布时间:2022-05-24
下一篇:
C# AstarPath类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap