/** * @deprecated use #writePrivateKey(java.io.OutputStream out, byte[] passphrase) */ public void setPassphrase(String passphrase){ if(passphrase==null || passphrase.length()==0){ setPassphrase((byte[])null); } else{ setPassphrase(Util.str2byte(passphrase)); } }
public void setPassphrase(String passphrase){ if(passphrase==null || passphrase.length()==0){ setPassphrase((byte[])null); } else{ setPassphrase(Util.str2byte(passphrase)); } } public void setPassphrase(byte[] passphrase){
/** * @deprecated use #writePrivateKey(java.io.OutputStream out, byte[] passphrase) */ public void setPassphrase(String passphrase){ if(passphrase==null || passphrase.length()==0){ setPassphrase((byte[])null); } else{ setPassphrase(Util.str2byte(passphrase)); } }
/** * Sets a passphrase for the private key. This will be * used for encrypting the private key before writing * it out. * @deprecated use #writePrivateKey(java.io.OutputStream out, byte[] passphrase) */ public void setPassphrase(String passphrase){ if(passphrase==null || passphrase.length()==0){ setPassphrase((byte[])null); } else{ setPassphrase(Util.str2byte(passphrase)); } }
public void changePassphrase(char[] newPassphrase) throws SshException { if (kpair.isEncrypted()) { throw new SshException(SshException.PASSPHRASE_REQUIRED, "Key is currently encrypyted. Please decrypt before changing passphrase."); } kpair.setPassphrase(new String(newPassphrase)); }
/** * return a "public" -> rsa public key, "private" -> its corresponding * private key */ public static Map<String,String> generate(String passPhrase) throws JSchException { com.jcraft.jsch.KeyPair pair = com.jcraft.jsch.KeyPair.genKeyPair( new JSch(), com.jcraft.jsch.KeyPair.RSA); if (passPhrase != null) { pair.setPassphrase(passPhrase); } ByteArrayOutputStream publicKeyOut = new ByteArrayOutputStream(); ByteArrayOutputStream privateKeyOut = new ByteArrayOutputStream(); pair.writePublicKey(publicKeyOut, "whirr"); pair.writePrivateKey(privateKeyOut); String publicKey = new String(publicKeyOut.toByteArray()); String privateKey = new String(privateKeyOut.toByteArray()); return ImmutableMap.<String, String> of("public", publicKey, "private", privateKey); }
/** * return a "public" -> rsa public key, "private" -> its corresponding * private key */ public static Map<String,String> generate(String passPhrase) throws JSchException { com.jcraft.jsch.KeyPair pair = com.jcraft.jsch.KeyPair.genKeyPair( new JSch(), com.jcraft.jsch.KeyPair.RSA); if (passPhrase != null) { pair.setPassphrase(passPhrase); } ByteArrayOutputStream publicKeyOut = new ByteArrayOutputStream(); ByteArrayOutputStream privateKeyOut = new ByteArrayOutputStream(); pair.writePublicKey(publicKeyOut, "whirr"); pair.writePrivateKey(privateKeyOut); String publicKey = new String(publicKeyOut.toByteArray()); String privateKey = new String(privateKeyOut.toByteArray()); return ImmutableMap.<String, String> of("public", publicKey, "private", privateKey); }
KeyPair kpair=KeyPair.genKeyPair(jsch, KeyPair.RSA, 2048); if (password.length > 0) { kpair.setPassphrase(Arrays.toString(password));
/** * Creates private and public ssh-rsa keys and stores them to the given * paths. The key is created while using the given pass phrase. * * @param passPhrase * the pass phrase to set to the new key * @param privateKeyPath * the path where the new private key gets stored * @param publicKeyPath * the path where the new public key gets stored * @return * @throws OpenShiftException * if the key could not be created */ public static SSHKeyPair create(SSHKeyType type, String passPhrase, String privateKeyPath, String publicKeyPath) throws OpenShiftException { try { KeyPair keyPair = KeyPair.genKeyPair(new JSch(), KeyPair.RSA, KEYLENGTH); keyPair.setPassphrase(passPhrase); keyPair.writePublicKey(publicKeyPath, "created by " + ID); keyPair.writePrivateKey(privateKeyPath); return new SSHKeyPair(keyPair, privateKeyPath, publicKeyPath, SSHKeyType.SSH_RSA); } catch (Exception e) { throw new OpenShiftException(e, "Could not create new rsa key", e); } }
/** * Creates private and public ssh-rsa keys and stores them to the given * paths. The key is created while using the given pass phrase. * * @param passPhrase * the pass phrase to set to the new key * @param privateKeyPath * the path where the new private key gets stored * @param publicKeyPath * the path where the new public key gets stored * @return * @throws OpenShiftException * if the key could not be created */ public static SSHKeyPair create(SSHKeyType type, String passPhrase, String privateKeyPath, String publicKeyPath) throws OpenShiftException { try { KeyPair keyPair = KeyPair.genKeyPair(new JSch(), KeyPair.RSA, KEYLENGTH); keyPair.setPassphrase(passPhrase); keyPair.writePublicKey(publicKeyPath, "created by " + ID); keyPair.writePrivateKey(privateKeyPath); return new SSHKeyPair(keyPair, privateKeyPath, publicKeyPath, SSHKeyType.SSH_RSA); } catch (Exception e) { throw new OpenShiftException(e, "Could not create new rsa key", e); } }
kPairCopy.setPassphrase(new String(passphrase)); kPairCopy.writePrivateKey(tempFile.getAbsolutePath()); kPairCopy = KeyPair.load(jsch, tempFile.getAbsolutePath());