private static void CreateInitFile(String filePath) { RSA rsa = RSA.Create(); string xmlString = RSAKeyExtensions.ToXmlString(rsa, true); File.WriteAllText(filePath, xmlString); }
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); }
public Product() { _key = RSA.Create(); _id = Guid.NewGuid(); _issuedLicenses = new ObservableCollection <License>(); _publicKey = RSAKeyExtensions.ToXmlString(_key, false); _privateKey = RSAKeyExtensions.ToXmlString(_key, true); }
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; } } }