Ejemplo n.º 1
0
        public static Chilkat.SshKey RsaKeyPair()
        {
            Chilkat.SshKey key = new Chilkat.SshKey();

            bool success;
            int  numBits;
            int  exponent;

            numBits  = 2048;
            exponent = 65537;
            success  = key.GenerateRsaKey(numBits, exponent);
            //var sshKeyPair = new SshKeyPair();

            key.ToPuttyPrivateKey(false);
            if (!success)
            {
                RsaKeyPair();
            }
            return(key);
        }
Ejemplo n.º 2
0
        private async Task <bool> GenerateNewRsaKey(SshKeyCreateRequest request)
        {
            var    numBits = 2048;
            var    exponent = 65537;
            var    success = sshKey.GenerateRsaKey(numBits, exponent);
            string exportedPrivateKey, exportedPublicKey, exportedPpkKey;
            bool   exportEncrypted;

            if (success != true)
            {
                logger.LogDebug("Bad params passed to RSA key generation method.");
                return(false);
            }

            //  Export the RSA private key to OpenSSH, PuTTY, and XML and save.
            exportEncrypted = false;

            var fingerprint = sshKey.GenFingerprint();

            exportedPrivateKey = sshKey.ToOpenSshPrivateKey(exportEncrypted);
            exportedPpkKey     = sshKey.ToPuttyPrivateKey(exportEncrypted);
            exportedPublicKey  = sshKey.ToOpenSshPublicKey();

            var keyToInsert = new SshKey()
            {
                Fingerprint = fingerprint,
                Name        = request.Name,
                Pem         = exportedPrivateKey,
                Private     = exportedPpkKey,
                Public      = exportedPublicKey
            };

            if ((await sshKeyRepository.InsertAsync(keyToInsert)) > 0)
            {
                logger.LogInformation("Key insert.");

                return(true);
            }

            return(false);
        }