use of com.jcraft.jsch.KeyPair in project devspaces-images by redhat-developer.
the class SshManager method generatePair.
/**
* Generates and stores ssh pair for specified user.
*
* @param owner the id of the user who will be the owner of the ssh pair
* @param service service name pf ssh pair
* @param name name of pair
* @return instance of generated ssh pair
* @throws ConflictException when given ssh pair cannot be generated or created
* @throws ServerException when any other error occurs during ssh pair generating or creating
*/
public SshPairImpl generatePair(String owner, String service, String name) throws ServerException, ConflictException {
KeyPair keyPair;
try {
keyPair = KeyPair.genKeyPair(genJSch, 2, 2048);
} catch (JSchException e) {
throw new ServerException("Failed to generate ssh pair.", e);
}
ByteArrayOutputStream privateBuff = new ByteArrayOutputStream();
keyPair.writePrivateKey(privateBuff);
ByteArrayOutputStream publicBuff = new ByteArrayOutputStream();
keyPair.writePublicKey(publicBuff, null);
final SshPairImpl generatedSshPair = new SshPairImpl(owner, service, name, publicBuff.toString(), privateBuff.toString());
sshDao.create(generatedSshPair);
return generatedSshPair;
}
use of com.jcraft.jsch.KeyPair in project confij by keykey7.
the class GitResourceSshTest method createKeyPair.
private static Path createKeyPair(Path privateKeyFile) throws Exception {
JSch jsch = new JSch();
KeyPair pair = KeyPair.genKeyPair(jsch, KeyPair.RSA, 2048);
try (OutputStream out = new FileOutputStream(privateKeyFile.toFile())) {
pair.writePrivateKey(out);
}
Path publicKeyFile = privateKeyFile.getParent().resolve(privateKeyFile.getFileName() + ".pub");
try (OutputStream out = new FileOutputStream(publicKeyFile.toFile())) {
pair.writePublicKey(out, TEST_USER);
}
return publicKeyFile;
}
use of com.jcraft.jsch.KeyPair in project confij by keykey7.
the class GitResourceSshTest method createHostKey.
private static byte[] createHostKey(OutputStream publicKey) throws Exception {
JSch jsch = new JSch();
KeyPair pair = KeyPair.genKeyPair(jsch, KeyPair.RSA, 2048);
pair.writePublicKey(publicKey, "");
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
pair.writePrivateKey(out);
out.flush();
return out.toByteArray();
}
}
Aggregations