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; } } }
public static void validateKeyPair(byte[] pub, byte[] priv) throws Exception { JSch j = new JSch(); com.jcraft.jsch.KeyPair.load(j, priv, pub); }
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{
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 prvkey, String pubkey) throws JSchException{
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{
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 GSISSHIdentityFile newInstance(String name, byte[] prvkey, byte[] pubkey, JSch jsch) throws JSchException{ KeyPair kpair = KeyPair.load(jsch, prvkey, pubkey); return new GSISSHIdentityFile(jsch, name, kpair); }
/** * Creates a new IdentityFile instance from the public * and private key data. * The private key array will be zeroed out after reading. */ static IdentityFile newInstance(String name, byte[] prvkey, byte[] pubkey, JSch jsch) throws JSchException{ KeyPair kpair = KeyPair.load(jsch, prvkey, pubkey); return new IdentityFile(jsch, name, kpair); }
/** * Creates a new IdentityFile instance from the public and private key * file names. */ static IdentityFile newInstance(String prvfile, String pubfile, JSch jsch) throws JSchException{ KeyPair kpair = KeyPair.load(jsch, prvfile, pubfile); return new IdentityFile(jsch, prvfile, kpair); }
static IdentityFile newInstance(String prvfile, String pubfile, JSch jsch) throws JSchException { KeyPair kpair = KeyPair.load(jsch, prvfile, pubfile); return new IdentityFile(prvfile, kpair); }
static IdentityFile newInstance(String prvfile, String pubfile, JSch jsch) throws JSchException{ KeyPair kpair = KeyPair.load(jsch, prvfile, pubfile); return new IdentityFile(jsch, prvfile, kpair); }
public static GSISSHIdentityFile newInstance(String prvfile, String pubfile, JSch jsch) throws JSchException{ KeyPair kpair = KeyPair.load(jsch, prvfile, pubfile); return new GSISSHIdentityFile(jsch, prvfile, kpair); }
static IdentityFile newInstance(String name, byte[] prvkey, byte[] pubkey, JSch jsch) throws JSchException { KeyPair kpair = KeyPair.load(jsch, prvkey, pubkey); return new IdentityFile(name, kpair); }
static IdentityFile newInstance(String name, byte[] prvkey, byte[] pubkey, JSch jsch) throws JSchException{ KeyPair kpair = KeyPair.load(jsch, prvkey, pubkey); return new IdentityFile(jsch, name, kpair); }
static IdentityFile newInstance(String prvfile, String pubfile, JSch jsch) throws JSchException{ KeyPair kpair = KeyPair.load(jsch, prvfile, pubfile); return new IdentityFile(jsch, prvfile, kpair); }
static IdentityFile newInstance(String name, byte[] prvkey, byte[] pubkey, JSch jsch) throws JSchException{ KeyPair kpair = KeyPair.load(jsch, prvkey, pubkey); return new IdentityFile(jsch, name, kpair); }
@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; }
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 void generatePublicKey(File file) throws IOException, JSchException { KeyPair kpair = KeyPair.load(jsch, getPrivateKey().getAbsolutePath()); kpair.writePublicKey(file.getAbsolutePath(), PUBLIC_KEY_COMMENT); kpair.dispose(); } }
public SshPrivateKeyFile createPrivateKeyFromStream(InputStream in) throws SshException { try { File file = toTemporaryFile(in, ""); KeyPair kpair = KeyPair.load(jsch, file.getAbsolutePath()); return new JschPrivateKeyFile(kpair); } catch (JSchException e) { throw new SshException(e); } catch (IOException ioe) { throw new SshException(SshException.IO_ERROR, ioe); } }