Refine search
public SSHKeysHelper(Integer keyLength) { try { keyPair = KeyPair.genKeyPair(new JSch(), KeyPair.RSA, keyLength); } catch (JSchException e) { e.printStackTrace(); } }
public String getPrivateKey() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); keyPair.writePrivateKey(baos); return baos.toString(); }
public String getPublicKey() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); keyPair.writePublicKey(baos, ""); return baos.toString(); }
public static String generateKeyPair(Context context) { JSch jsch = new JSch(); KeyPair kpair = null; try { kpair = KeyPair.genKeyPair(jsch, KeyPair.RSA); kpair.writePrivateKey(context.getFilesDir().getAbsoluteFile() + "/" + AuthData.PRIVATE_KEY); kpair.writePublicKey(context.getFilesDir().getAbsoluteFile() + "/" + AuthData.PUBLIC_KEY, "MobileOrgPubKey"); } catch (JSchException | IOException e){ Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show(); return ""; } return AuthData.getPublicKey(context); }
@Override protected JSch createDefaultJSch(FS fs) throws JSchException { JSch jsch = new JSch(); PrivateKeyUtils.migratePrivateKeys(); File sshDir = PrivateKeyUtils.getPrivateKeyFolder(); for (File file : sshDir.listFiles()) { KeyPair kpair = KeyPair.load(jsch, file.getAbsolutePath()); jsch.addIdentity(file.getAbsolutePath()); } return jsch; }
char[] password = getServerPassPhrase().getPassword(); JSch jsch=new JSch(); KeyPair kpair=KeyPair.genKeyPair(jsch, KeyPair.RSA, 2048); if (password.length > 0) { kpair.setPassphrase(Arrays.toString(password)); kpair.writePrivateKey(privateKeyFile.getAbsolutePath()); kpair.writePublicKey(publicKeyFile.getAbsolutePath(), vcsLogin + "@forIsisFish"); if (log.isInfoEnabled()) { log.info("Finger print: "+kpair.getFingerPrint()); kpair.dispose(); } catch (Exception e) { error=e;
public static File getPublicKeyEnsure(File privateKey) { File publicKey = getPublicKey(privateKey); if (!publicKey.exists()) { try { JSch jsch=new JSch(); KeyPair kpair=KeyPair.load(jsch, privateKey.getAbsolutePath()); kpair.writePublicKey(new FileOutputStream(publicKey), "sgit"); kpair.dispose(); } catch (Exception e) { //TODO e.printStackTrace(); } } return publicKey; }
private boolean isPrivateKeyFormatCorrect(JGitEnvironmentProperties sshUriProperties, ConstraintValidatorContext context) { try { KeyPair.load(new JSch(), sshUriProperties.getPrivateKey().getBytes(), null); return true; } catch (JSchException e) { context.buildConstraintViolationWithTemplate( format("Property '%sprivateKey' is not a valid private key", GIT_PROPERTY_PREFIX)) .addConstraintViolation(); return false; } } }
pairRepresentation = "(" + privateKeyPath + ", " + publicKeyPath + ")"; KeyPair pair = KeyPair.load(new JSch(), privateKeyPath, publicKeyPath); if (pair.isEncrypted()) { throw new ConfigurationException("Key pair " + pairRepresentation + " is encrypted. Try generating a new passwordless SSH keypair " +
private void generatePrivateKey(File file) throws IOException, JSchException { KeyPair kpair = KeyPair.genKeyPair(jsch, KeyPair.RSA, PRIVATE_KEY_LENGTH); kpair.writePrivateKey(file.getAbsolutePath()); kpair.dispose(); }
if (kpair.isEncrypted()) { throw new SshException(SshException.ENCRYPTED, "Attempt to access a private key that is currently encrypted."); kpair.writePrivateKey(tempFile.getAbsolutePath()); KeyPair kPairCopy = KeyPair.load(jsch, tempFile.getAbsolutePath()); if (passphrase != null) { kPairCopy.setPassphrase(new String(passphrase)); kPairCopy.writePrivateKey(tempFile.getAbsolutePath()); kPairCopy = KeyPair.load(jsch, tempFile.getAbsolutePath()); kPairCopy.decrypt(new String(passphrase));
private void generatePublicKey(File file) throws IOException, JSchException { KeyPair kpair = KeyPair.load(jsch, getPrivateKey().getAbsolutePath()); kpair.writePublicKey(file.getAbsolutePath(), PUBLIC_KEY_COMMENT); kpair.dispose(); } }
public static KeyPair create() { com.jcraft.jsch.KeyPair k; synchronized (jsch) { try { k = com.jcraft.jsch.KeyPair.genKeyPair(jsch, DEFAULT_KEY_TYPE, DEFAULT_KEY_SIZE); } catch (JSchException e) { throw new SecurityException(e); } } byte[] publicKey = array(out -> k.writePublicKey(out, DEFAULT_KEY_COMMENT)); byte[] privateKey = array(k::writePrivateKey); return new KeyPair(publicKey, privateKey); }
public static KeyPair load(JSch jsch, String prvkey) throws JSchException{ String pubkey=prvkey+".pub"; if(!new File(pubkey).exists()){ pubkey=null; } return load(jsch, prvkey, pubkey); } public static KeyPair load(JSch jsch, String prvfile, String pubfile) throws JSchException{
/** * Creates a new key pair with default key size of 1024 bits. * @param jsch the JSch object used for configuration purposes. * @param type one of {@link #DSA} and {@link #RSA}. * @return null if a unknown type constant is given, else the new * key pair. */ public static KeyPair genKeyPair(JSch jsch, int type) throws JSchException{ return genKeyPair(jsch, type, 1024); }
@Override public void clear() { keyPair.dispose(); } };
/** * Decrypts this identity with the specified pass-phrase. * @param passphrase the pass-phrase for this identity. * @return <tt>true</tt> if the decryption is succeeded * or this identity is not cyphered. */ public boolean setPassphrase(byte[] passphrase) throws JSchException{ return kpair.decrypt(passphrase); }
/** * Returns <tt>true</tt> if this identity is cyphered. * * @return <tt>true</tt> if this identity is cyphered. */ @Override public boolean isEncrypted() { return kpair.isEncrypted(); }
/** * Returns the public-key blob. * @return the public-key blob */ public byte[] getPublicKeyBlob(){ return kpair.getPublicKeyBlob(); }
/** * Returns the finger-print of the public key. * * @return finger print */ public String getFingerPrint() { if (hash == null) hash = genHash(); byte[] kblob = getPublicKeyBlob(); if (kblob == null) return null; return Util.getFingerPrint(hash, kblob); }