示例#1
0
        public async Task <string> GenerateKey(string data)
        {
            var key             = asym.CreateKeyPair(512);
            var publicKey       = key.ExportPublicKey();
            var publicKeyString = Convert.ToBase64String(publicKey);

            return(await Task.FromResult(publicKeyString));
        }
    public void KeyPairRoundTrip(AsymmetricAlgorithm algorithm, int keySize, CryptographicPrivateKeyBlobType format)
    {
        IAsymmetricKeyAlgorithmProvider keyAlgorithm = WinRTCrypto.AsymmetricKeyAlgorithmProvider.OpenAlgorithm(algorithm);

        using (ICryptographicKey key = keyAlgorithm.CreateKeyPair(keySize))
        {
            byte[] keyBlob = key.Export(format);
            using (var key2 = keyAlgorithm.ImportKeyPair(keyBlob, format))
            {
                byte[] key2Blob = key2.Export(format);

                Assert.Equal(Convert.ToBase64String(keyBlob), Convert.ToBase64String(key2Blob));
                this.logger.WriteLine(Convert.ToBase64String(keyBlob));
            }
        }
    }
    public void LegalKeySizes(AsymmetricAlgorithm name, int minSize, int maxSize, int stepSize)
    {
        IAsymmetricKeyAlgorithmProvider provider = WinRTCrypto.AsymmetricKeyAlgorithmProvider.OpenAlgorithm(name);
        IReadOnlyList <KeySizes>?       result   = provider.LegalKeySizes;

        Assert.NotNull(result);
        Assert.NotEmpty(result);

        Action <int> attemptKeySize = size =>
        {
            provider.CreateKeyPair(size).Dispose();
        };

        KeySizes range = result.Single();

        Assert.Equal(minSize, range.MinSize);
        Assert.Equal(maxSize, range.MaxSize);
        Assert.Equal(stepSize, range.StepSize);
    }
示例#4
0
        public static ICryptographicKey CreateKey(int keySize = 2048)
        {
            IAsymmetricKeyAlgorithmProvider provider = WinRTCrypto.AsymmetricKeyAlgorithmProvider.OpenAlgorithm(AsymmetricAlgorithm.RsaPkcs1);

            return(provider.CreateKeyPair(keySize));
        }