예제 #1
0
        /// <summary>
        /// Creates Rsa Key pair and saves it inside KeyManager.
        /// </summary>
        /// <param name="privateKeyAlias">The name of a private Key.</param>
        /// <param name="publicKeyAlias">The name of a public Key.</param>
        public void CreateRsaKeyPair(string privateKeyAlias, string publicKeyAlias) // You can extend this method to support password protection.
        {
            if (publicKeyAlias == null || privateKeyAlias == null)
            {
                throw new System.ArgumentException("Argument is \"null\"");
            }

            // Checks if Keys exist in KeyManager under this aliases.
            if (!(this.Exists(privateKeyAlias) && !this.Exists(publicKeyAlias)))
            {
                try
                {
                    KeyManager.CreateRsaKeyPair(1024, privateKeyAlias, publicKeyAlias, new Policy(), new Policy()); // USE 4096 in real application!!!!, lowered to speed up.
                }
                catch (Exception ex)
                {
                    Log.Error("SecureRepository_KEYS", ex.Message);
                }
            }
            else
            {
                Log.Error("SecureRepository_KEYS", "Alias already in use.");
            }
        }