public ActionResult publicKey([FromHeader] string key) { if (String.IsNullOrEmpty(key)) { throw new ArgumentNullException("Couldn't get the public key"); } if (UserDatabaseAccess.keyCheck(key)) { byte[] dataToChange = Encoding.ASCII.GetBytes(key); byte[] encrpyt; byte[] decryptData; RSAParameters publicKey; RSAParameters privateKey; string str; using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider()) { rsa.PersistKeyInCsp = true; publicKey = rsa.ExportParameters(false); privateKey = rsa.ExportParameters(true); encrpyt = RSAInternal.RSAEncrypt(dataToChange, publicKey); str = RSACryptoExtensions.ToXmlStringCore22(rsa, false); decryptData = RSAInternal.RSADecrypt(encrpyt, privateKey); RSACryptoExtensions.FromXmlStringCore22(rsa, str); } return(Ok(str)); } else { return(Ok("ApiKey invalid")); } }
static public string getPublicKey() { string key = RSACryptoExtensions.ToXmlStringCore22(rsa, false); return(key); }