本文整理汇总了Java中java.security.interfaces.DSAKeyPairGenerator类的典型用法代码示例。如果您正苦于以下问题:Java DSAKeyPairGenerator类的具体用法?Java DSAKeyPairGenerator怎么用?Java DSAKeyPairGenerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DSAKeyPairGenerator类属于java.security.interfaces包,在下文中一共展示了DSAKeyPairGenerator类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateKey
import java.security.interfaces.DSAKeyPairGenerator; //导入依赖的package包/类
/** Generate a key pair
@param type DSA or RSA
@param size the length
@param password the password to use to encrypted the key
@param keyfile the keyfile to store the key in
@param newParams generate new parameters if using DSA--by default Sun uses fixed precomputed params
@return the keypair
@exception NoSuchAlgorithmException if you choose a key we don't know about
@exception NoSuchProviderException internal errors
@exception IOException encoding errors
*/
public static KeyPair generateKey(String type,int size,
String password,BufferedWriter keyfile,boolean newParams)
throws NoSuchAlgorithmException, NoSuchProviderException, IOException {
PrivateKey priv;
KeyPairGenerator kg;
if(type.equals("DSA")){
kg=KeyPairGenerator.getInstance(type);
DSAKeyPairGenerator dsaGen=(DSAKeyPairGenerator)kg;
dsaGen.initialize(size,newParams,new SecureRandom());
}
else{
kg=KeyPairGenerator.getInstance(type,"Cryptix");
kg.initialize(size);
}
KeyPair pair=kg.generateKeyPair();
// We need to map the DSA keys given us by Sun into
// our own DSA keys because Sun gives us a bogus
// DER encoding
if(type.equals("DSA")){
priv=new EAYDSAPrivateKey((DSAPrivateKey)pair.getPrivate());
}
else {
priv=new X509RSAPrivateKey((CryptixRSAPrivateKey)pair.getPrivate());
}
EAYEncryptedPrivateKey.writePrivateKey(priv,password.getBytes(),keyfile);
return pair;
}