Easy-keygen
Easy to use, multiplataform ssh-keygen for Node.JS. Can return the keys as string or as buffer.
Requirements
Linux /MaOS
- ES2015
Windows
- GitBash
- "C:\Program Files\Git\usr\bin" must be available on the PATH environment variable.
Usage
$ npm install easy-keygen
const keygen = ;;/* Will return something like beneth: -----BEGIN RSA PRIVATE KEY-----MIIEowIBAAKCAQEA3dTa07ltbtGjy0E31fNuvJAzSZXArgQVuAOlIN+/z8z9d54bv8LqcfT36x5TtLVpcNom0PLF3KLbvsk707HzcpIBXcfJc0/Wqb7EfrwcIlfC8f972N/5FhUMXOgSWXNkDtKpevQ3yQmuUlDvp3gaJ9e/ZVNExYydRm/W5Rg17NOXP/xLLPhcdAko/VlwOACI14E1N8mZmO+/NxAJiTAVH1bHVKbnN+MOIETrYTrWoMJ6zSM9j5lzFz/C7/EQIH2/0qRMLeFSzgUN4Sr3TCZ61L0ab2ceAesXjN28fuoAOuBRpq153KY268bWV57OXrHS554mYFO0OYUYAIVutn5v8QIDAQABAoIBAFl24fYnv4HFHLj5iYpJDi0QPw77TWUhEp1PIwa6FoK5GrRmWKyi8Kia8m2ponqr+2VfJe55KuFL8THluLIs/5ECX3ix/YX6+gklfdvbA8G6AU5WCl2yHqKIlxcpJVVcG0t7HI0Q93ql498g8zZoUqwk7/Tuezrs9fUVX+avN/hVsP1ia4Pe4RGLSt2TAWPxo12ObO18SdBmfX6geo30r/JuqaOiTCpLvJlqBCyfcHTQOwaI7XenfEddKE1im80Avh4UtY0UwR4H5ye51mA1gsfMEb1NK9s9RvO0w8ba3msUzFw+s8dG6gq7hrhh5jNtw9bcKiPrXzYZs2542TwR3cECgYEA/dJrpI5RS1kNV5NV+i8yVW6WiZ2tj5FQkVlJ+U7NylVXf0xuL9cb8jfG6wAPaqUI1xO92O2d5x9fioB1Fza7n8jz/8kYvfRRxOXcMIFjG6ce1XPO5dQ+Bn/2Vtt5aRaSxKmFj8hgAahr385n+RtKWgcelwTLRMUIrY9zqqRS9XkCgYEA37wo4V6n8uRVg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ecomputer-1234-123*/
With no arguments the key pair will no be persisted, to save the key pair you need to pass a path like beneth:
const keygen = ;const fs = ; ;/** - This wil have the same result as the aobe, but the certificates will be saved as cert, and cert.pub*/
Warning: If the path for your cetificates are the same of any other files with the same name they will be erased unless you set options.prevent = true. In this case there will be an error.
Options
You cam pass an object with one to five options
- Buffer: {'buffer': true}. Will return the key im buffer format, instead of string. Usefull for payload generation.
- Authentication type: {'type': 'rsa'}. Is the type of authentivation on the certificate that will be generated. The default is RSA. (refere to ssh-keygen -? or Choosing_the_authentication_key_type for more information on SSH keys authentication types.)
- Passphrase: {'passphrase': 'secret phrase goes here'}. Is the passprase. It will be required for future decription if set.
- SSH key size: {'size': 1024}. Sets the size, in bits, of the key pair genareated, the bigger the size longer the it will take to genarate the key pair. (A long key pair with 9216 may take over 5 seconds, depending on the sistema resources.)
- Prevent rewrite: {'prevent': true}. Will prevent the re-write of the file with the same name as the end of the path option. (The script may freeze case there is an file with the same name.)
const keygen = ;const fs = ; ;/** - This wil have a result similar to the first example, but the certificates will be saved as cert, and cert.pub, will have 3096 bits oz size, and will be DSA type.*/
To return a buffer data
const keygen = ;const fs = ; ;/** Will return something like: <Buffer 2d 2d 2d 2d 2d 42 45 47 49 4e 20 52 53 41 20 50 52 49 56 41 54 45 20 4b 45 59 2d 2d 2d 2d 2d 0a 4d 49 49 45 6f 77 49 42 41 41 4b 43 41 51 45 41 73 6b ... > <Buffer 73 73 68 2d 72 73 61 20 41 41 41 41 42 33 4e 7a 61 43 31 79 63 32 45 41 41 41 41 44 41 51 41 42 41 41 41 42 41 51 43 79 53 69 39 65 4a 4a 31 50 76 68 ... >*/
Testing
$ npm test/** the dev dependencies must be installed.*/