非對稱型加密非常適合多個客戶端和服務器之間的秘密通訊
非對稱型加密也有它先天的缺點
import java
import java
import javax
import javax
/**
* <p>Title: RSA非對稱型加密的公鑰和私鑰</p>
* <p>Description: </p>
* <p>Copyright: Copyright (c)
* <p>Company: </p>
* @author not attributable
* @version
*/
public class KeyRSA {
private KeyPairGenerator kpg = null;
private KeyPair kp = null;
private PublicKey public_key = null;
private PrivateKey private_key = null;
private FileOutputStream public_file_out = null;
private ObjectOutputStream public_object_out = null;
private FileOutputStream private_file_out = null;
private ObjectOutputStream private_object_out = null;
/**
* 構造函數
* @param in 指定密匙長度(取值范圍
* @throws NoSuchAlgorithmException 異常
*/
public KeyRSA(int in
{
kpg = KeyPairGenerator
kpg
kp = kpg
public_key = kp
private_key = kp
//保存公匙
public_file_out = new FileOutputStream(address +
public_object_out = new ObjectOutputStream(public_file_out);
public_object_out
//保存私匙
private_file_out = new FileOutputStream(address +
private_object_out = new ObjectOutputStream(private_file_out);
private_object_out
}
public static void main(String[] args) {
try {
System
new KeyRSA(
}
catch (IOException ex) {
}
catch (NoSuchAlgorithmException ex) {
}
}
}
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26592.html