Example #1
0
        // Generates keys for RSA signing
        public IxianKeyPair generateKeys(int keySize, bool skip_header = false)
        {
            KeyPair kp = null;

            try
            {
                KeyPairGenerator kpg = KeyPairGenerator.GetInstance("RSA");
                kpg.Initialize(keySize);
                kp = kpg.GenKeyPair();
                IxianKeyPair ixi_kp = new IxianKeyPair();
                ixi_kp.privateKeyBytes = rsaKeyToBytes(kp, true, skip_header);
                ixi_kp.publicKeyBytes  = rsaKeyToBytes(kp, false, skip_header);

                byte[] plain = Encoding.UTF8.GetBytes("Plain text string");
                if (!testKeys(plain, ixi_kp))
                {
                    return(null);
                }
                return(ixi_kp);
            }
            catch (Exception e)
            {
                Logging.warn(string.Format("Exception while generating signature keys: {0}", e.ToString()));
                return(null);
            }
        }
Example #2
0
        /// <exception cref="NoSuchAlgorithmException"/>
        public static KeyPair GenerateKeyPair(string algorithm)
        {
            KeyPairGenerator keyGen = KeyPairGenerator.GetInstance(algorithm);

            keyGen.Initialize(1024);
            return(keyGen.GenKeyPair());
        }