File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -577,3 +577,22 @@ Options are
577
577
(disconnect channel))
578
578
(when-not (or session-given channel-given)
579
579
(disconnect session))))))
580
+
581
+
582
+
583
+ (defvar- key-types {:rsa KeyPair/RSA :dsa KeyPair/DSA})
584
+
585
+ (defn generate-keypair
586
+ " Generate a keypair, returned as [private public] byte arrays.
587
+ Valid types are :rsa and :dsa. key-size is in bytes. passphrase
588
+ can be a string or byte array."
589
+ ([key-type key-size passphrase]
590
+ (generate-keypair *ssh-agent* key-type key-size passphrase))
591
+ ([agent key-type key-size passphrase]
592
+ (let [keypair (KeyPair/genKeyPair agent (key-type key-types) key-size)]
593
+ (when passphrase (.setPassphrase keypair passphrase))
594
+ (let [pub-baos (java.io.ByteArrayOutputStream. )
595
+ pri-baos (java.io.ByteArrayOutputStream. )]
596
+ (.writePublicKey keypair pub-baos " " )
597
+ (.writePrivateKey keypair pri-baos)
598
+ [(.toByteArray pri-baos) (.toByteArray pub-baos)]))))
Original file line number Diff line number Diff line change @@ -424,3 +424,7 @@ list, Alan Dipert and MeikelBrandmeyer."
424
424
(with-default-session-options {:strict-host-key-checking :no }
425
425
(test-sftp-transient-with " localhost" :username (username )))))
426
426
427
+ (deftest generate-keypair-test
428
+ (with-ssh-agent []
429
+ (let [[priv pub] (generate-keypair :rsa 1024 " hello" )]
430
+ (add-identity *ssh-agent* " name" priv pub (.getBytes " hello" )))))
You can’t perform that action at this time.
0 commit comments