Package com.jcraft.jsch

Examples of com.jcraft.jsch.KeyPair.dispose()


    private static String key() throws Exception {
        final ByteArrayOutputStream stream = new ByteArrayOutputStream();
        try {
            final KeyPair kpair = KeyPair.genKeyPair(new JSch(), KeyPair.DSA);
            kpair.writePublicKey(stream, "");
            kpair.dispose();
        } finally {
            stream.close();
        }
        return new String(stream.toByteArray());
    }
View Full Code Here


    private String key() throws Exception {
        final ByteArrayOutputStream stream = new ByteArrayOutputStream();
        try {
            final KeyPair kpair = KeyPair.genKeyPair(new JSch(), KeyPair.DSA);
            kpair.writePublicKey(stream, "");
            kpair.dispose();
        } finally {
            stream.close();
        }
        return new String(stream.toByteArray());
    }
View Full Code Here

            String password = generateRandomString();
            // We are encrypting the private key with the hash of (tokenId+password).
            // Any client which wants to use this private key will also generate a hash and then use it to decrypt the key. 
            kpair.writePrivateKey(fileName,password.getBytes());
            kpair.writePublicKey(fileName + ".pub"  , "");
            kpair.dispose();
            byte[] priKey = FileUtils.readFileToByteArray(new File(fileName));
            byte[] pubKey = FileUtils.readFileToByteArray(new File(fileName + ".pub"));
            SSHCredential sshCredential = new SSHCredential();
            sshCredential.setPrivateKey(priKey);
            sshCredential.setPublicKey(pubKey);
View Full Code Here

            String password = generateRandomString();
            // We are encrypting the private key with the hash of (tokenId+password).
            // Any client which wants to use this private key will also generate a hash and then use it to decrypt the key. 
            kpair.writePrivateKey(fileName,generateHash(tokenId,password).getBytes());
            kpair.writePublicKey(fileName + ".pub"  , "");
            kpair.dispose();
            byte[] priKey = FileUtils.readFileToByteArray(new File(fileName));
            byte[] pubKey = FileUtils.readFileToByteArray(new File(fileName + ".pub"));
            SSHCredential sshCredential = new SSHCredential();
            sshCredential.setPrivateKey(priKey);
            sshCredential.setPublicKey(pubKey);
View Full Code Here

            KeyPair kpair = KeyPair.genKeyPair(jsch, KeyPair.RSA);

            kpair.writePrivateKey(new FileOutputStream(priv));
            kpair.writePublicKey(new FileOutputStream(pub), "Test");
            System.out.println("Finger print: " + kpair.getFingerPrint());
            kpair.dispose();
            return new KeyPairFiles(priv, pub);
        } else {
            System.out.println("Test key-pair seems to already exist.");
            return new KeyPairFiles(priv, pub);
        }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.