本文整理汇总了Java中com.jcraft.jsch.KeyPair.dispose方法的典型用法代码示例。如果您正苦于以下问题:Java KeyPair.dispose方法的具体用法?Java KeyPair.dispose怎么用?Java KeyPair.dispose使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.jcraft.jsch.KeyPair
的用法示例。
在下文中一共展示了KeyPair.dispose方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createKeyPair
import com.jcraft.jsch.KeyPair; //导入方法依赖的package包/类
public List<File> createKeyPair() {
List<File> keyFileList = new ArrayList<>();
try{
File privateKeyFile = File.createTempFile(Constants.KEY_FILE_PREFIX, Constants.CHAR_EMPTY);
File publicKeyFile = new File(privateKeyFile.getAbsolutePath() + Constants.KEY_FILE_SUFFIX);
KeyPair keyPair = KeyPair.genKeyPair(JSCH, KeyPair.RSA);
keyPair.writePrivateKey(privateKeyFile.getAbsolutePath());
keyPair.writePublicKey(publicKeyFile.getAbsolutePath(), COMMENT);
keyPair.dispose();
keyFileList.add(privateKeyFile);
keyFileList.add(publicKeyFile);
}
catch(Exception e){
LOG.error(e.getMessage(), e);
}
return keyFileList;
}
示例2: keyGen
import com.jcraft.jsch.KeyPair; //导入方法依赖的package包/类
public Map<String,String> keyGen(String passPhrase, String pubDesc) {
JSch jsch=new JSch();
String passphrase= (passPhrase == null) ? "" : passPhrase;
Map<String,String> result = new HashMap<String,String>();
try{
KeyPair kpair=KeyPair.genKeyPair(jsch, KeyPair.RSA, 2048);
kpair.setPassphrase(passphrase);
OutputStream prkos = new ByteArrayOutputStream();
kpair.writePrivateKey(prkos);
String privateKey = prkos.toString();
//removing "\n" at the end of the string
result.put("private", privateKey.substring(0, privateKey.length() - 1));
OutputStream pubkos = new ByteArrayOutputStream();
kpair.writePublicKey(pubkos, pubDesc);
String pubKey = pubkos.toString();
//removing "\n" at the end of the string
result.put("public", pubKey.substring(0, pubKey.length() - 1));
kpair.dispose();
return result;
} catch(Exception e){
System.out.println(e);
logger.error(e.getMessage());
throw new TransistorException(CmsError.TRANSISTOR_EXCEPTION, e.getMessage());
}
}
示例3: generateNewIdentity
import com.jcraft.jsch.KeyPair; //导入方法依赖的package包/类
public static final void generateNewIdentity(File keyDir, String comment, int strength) throws Exception {
JSch jsch = new JSch();
KeyPair newKeyPair = KeyPair.genKeyPair(jsch, KeyPair.RSA, strength);
File privateKeyFile = new File(keyDir, "id_rsa");
File publicKeyFile = new File(keyDir, "id_rsa.pub");
if (privateKeyFile.exists()) {
privateKeyFile.delete();
}
if (publicKeyFile.exists()) {
publicKeyFile.delete();
}
newKeyPair.writePrivateKey(new FileOutputStream(privateKeyFile));
newKeyPair.writePublicKey(new FileOutputStream(publicKeyFile), comment);
newKeyPair.dispose();
}
示例4: genKeyPair
import com.jcraft.jsch.KeyPair; //导入方法依赖的package包/类
public void genKeyPair() {
createFilePath();
KeyPair kp = null;
try {
kp = KeyPair.genKeyPair(new JSch(), keypairType, keypairSize);
kp.writePrivateKey(keypairFileName);
kp.writePublicKey(keypairFileName + ".pub", keypairComment);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (kp != null) {
kp.dispose();
}
}
}
示例5: GetKeyprint
import com.jcraft.jsch.KeyPair; //导入方法依赖的package包/类
private String GetKeyprint(String keyfilePath, String passphrase) {
try {
KeyPair keyPair = KeyPair.load(new JSch(), keyfilePath);
if (!passphrase.isEmpty() && keyPair.isEncrypted())
keyPair.decrypt(passphrase);
else if (passphrase.isEmpty() && keyPair.isEncrypted()) {
Toast.makeText(this, R.string.error_key_need_pass, Toast.LENGTH_LONG).show();
return "";
}
String fingerprint = keyPair.getFingerPrint();
keyPair.dispose();
return fingerprint;
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
示例6: generateKeys
import com.jcraft.jsch.KeyPair; //导入方法依赖的package包/类
private void generateKeys() throws JSchException, IOException {
String instance_name = InstanceStatus.getStatic().summary.getInstanceName();
String host_name = InstanceStatus.getStatic().summary.getHostName();
String comment = "mydmam-" + instance_name + "@" + host_name;
JSch jsch = new JSch();
KeyPair kpair = KeyPair.genKeyPair(jsch, KeyPair.RSA);
kpair.writePrivateKey(private_key);
kpair.writePublicKey(public_key, comment);
kpair.dispose();
String os_name = System.getProperty("os.name").toLowerCase();
if (os_name.indexOf("win") == -1) {
ArrayList<String> params = new ArrayList<String>();
params.add("600");
params.add(private_key);
ExecprocessGettext exec = new ExecprocessGettext(ExecBinaryPath.get("chmod"), params);
exec.start();
}
Loggers.Ssh.info("Generate SSH Keys for MyDMAM, public key: " + new File(public_key) + ", private key: " + new File(private_key) + ", finger print: " + kpair.getFingerPrint());
}
示例7: generateRsaKey
import com.jcraft.jsch.KeyPair; //导入方法依赖的package包/类
@Override
public RSAKeyPair generateRsaKey() {
String comment = "FLOWCI";
int type = KeyPair.RSA;
final int keySize = 2048; // default 1024, bitbucket support at least 2048
JSch jsch = new JSch();
try {
KeyPair kpair = KeyPair.genKeyPair(jsch, type, keySize);
RSAKeyPair pair = new RSAKeyPair();
// private key
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
kpair.writePrivateKey(baos);
pair.setPrivateKey(baos.toString());
}
// public key
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
kpair.writePublicKey(baos, comment);
pair.setPublicKey(baos.toString());
}
kpair.dispose();
return pair;
} catch (JSchException | IOException e) {
return null;
}
}
示例8: key
import com.jcraft.jsch.KeyPair; //导入方法依赖的package包/类
/**
* Generates a random public key for test.
* @return The encoded SSH public key.
* @throws Exception If a problem occurs.
*/
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());
}
示例9: key
import com.jcraft.jsch.KeyPair; //导入方法依赖的package包/类
/**
* Generates a random public key for test.
*
* @return The encoded SSH public key.
* @throws Exception If a problem occurs.
*/
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());
}
示例10: generateKeyPair
import com.jcraft.jsch.KeyPair; //导入方法依赖的package包/类
/**
* Generates a rsa key-pair in /tmp/jenkins-testkey for use with authenticating the trigger against the mock
* server.
*
* @return the path to the private key file
*
* @throws IOException if so.
* @throws InterruptedException if interrupted while waiting for ssh-keygen to finish.
* @throws JSchException if creation of the keys goes wrong.
*/
public static KeyPairFiles generateKeyPair() throws IOException, InterruptedException, JSchException {
File tmp = new File(System.getProperty("java.io.tmpdir")).getCanonicalFile();
File priv = new File(tmp, "jenkins-testkey");
File pub = new File(tmp, "jenkins-testkey.pub");
if (!(priv.exists() && pub.exists())) {
if (priv.exists()) {
if (!priv.delete()) {
throw new IOException("Could not delete temp private key");
}
}
if (pub.exists()) {
if (!pub.delete()) {
throw new IOException("Could not delete temp public key");
}
}
System.out.println("Generating test key-pair.");
JSch jsch = new JSch();
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);
}
}
示例11: getPublicKeyEnsure
import com.jcraft.jsch.KeyPair; //导入方法依赖的package包/类
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;
}
示例12: generatePrivateKey
import com.jcraft.jsch.KeyPair; //导入方法依赖的package包/类
private void generatePrivateKey(File file) throws IOException, JSchException {
KeyPair kpair = KeyPair.genKeyPair(jsch, KeyPair.RSA, PRIVATE_KEY_LENGTH);
kpair.writePrivateKey(file.getAbsolutePath());
kpair.dispose();
}
示例13: generatePublicKey
import com.jcraft.jsch.KeyPair; //导入方法依赖的package包/类
private void generatePublicKey(File file) throws IOException, JSchException {
KeyPair kpair = KeyPair.load(jsch, getPrivateKey().getAbsolutePath());
kpair.writePublicKey(file.getAbsolutePath(), PUBLIC_KEY_COMMENT);
kpair.dispose();
}
示例14: generateKey
import com.jcraft.jsch.KeyPair; //导入方法依赖的package包/类
private void generateKey() {
String newFilename = mNewFilename.getText().toString().trim();
if (newFilename.equals("")) {
showToastMessage(R.string.alert_new_filename_required);
mNewFilename
.setError(getString(R.string.alert_new_filename_required));
return;
}
if (newFilename.contains("/")) {
showToastMessage(R.string.alert_filename_format);
mNewFilename.setError(getString(R.string.alert_filename_format));
return;
}
int key_size = Integer.parseInt(mKeyLength.getText().toString());
if (key_size < 1024) {
showToastMessage(R.string.alert_too_short_key_size);
mNewFilename.setError(getString(R.string.alert_too_short_key_size));
return;
}
if (key_size > 16384) {
showToastMessage(R.string.alert_too_long_key_size);
mNewFilename.setError(getString(R.string.alert_too_long_key_size));
return;
}
int type = mDSAButton.isChecked() ? KeyPair.DSA : KeyPair.RSA;
File newKey = new File(PrivateKeyUtils.getPrivateKeyFolder(), newFilename);
File newPubKey = new File(PrivateKeyUtils.getPublicKeyFolder(), newFilename);
try {
JSch jsch=new JSch();
KeyPair kpair=KeyPair.genKeyPair(jsch, type, key_size);
kpair.writePrivateKey(new FileOutputStream(newKey));
kpair.writePublicKey(new FileOutputStream(newPubKey), "sgit");
kpair.dispose();
} catch (Exception e) {
//TODO
e.printStackTrace();
}
((PrivateKeyManageActivity)getActivity()).refreshList();
}