Esempio n. 1
0
        private static void CreateInitFile(String filePath)
        {
            RSA    rsa       = RSA.Create();
            string xmlString = RSAKeyExtensions.ToXmlString(rsa, true);

            File.WriteAllText(filePath, xmlString);
        }
Esempio n. 2
0
        private RSAKeysPair GenerateKeys(RSAKeySize rsaKeySize)
        {
            int keySize = (int)rsaKeySize;

            if (keySize % 2 != 0 || keySize < 512)
            {
                throw new Exception("Key should be multiple of two and greater than 512.");
            }

            var rsaKeysTypes = new RSAKeysPair();

            using (var provider = new RSACryptoServiceProvider(keySize))
            {
                var publicKey  = RSAKeyExtensions.ToXmlString(provider, false);
                var privateKey = RSAKeyExtensions.ToXmlString(provider, true);

                var publicKeyWithSize  = IncludeKeyInEncryptionString(publicKey, keySize);
                var privateKeyWithSize = IncludeKeyInEncryptionString(privateKey, keySize);

                rsaKeysTypes.PublicKey  = publicKeyWithSize;
                rsaKeysTypes.PrivateKey = privateKeyWithSize;
            }

            return(rsaKeysTypes);
        }
Esempio n. 3
0
 public Product()
 {
     _key            = RSA.Create();
     _id             = Guid.NewGuid();
     _issuedLicenses = new ObservableCollection <License>();
     _publicKey      = RSAKeyExtensions.ToXmlString(_key, false);
     _privateKey     = RSAKeyExtensions.ToXmlString(_key, true);
 }
Esempio n. 4
0
        private (String priv, String pub) CreatePrivateAndPublicKey()
        {
            using (var rsa = new RSACryptoServiceProvider(2048))
            {
                try
                {
                    rsa.ExportParameters(false);
                    string pubKey = RSAKeyExtensions.ToXmlString(rsa, false);
                    rsa.ExportParameters(true);
                    string privKey = RSAKeyExtensions.ToXmlString(rsa, true);

                    return(privKey, pubKey);
                }
                finally
                {
                    rsa.PersistKeyInCsp = false;
                }
            }
        }