为什么我的运行结果完全不同?
为什么我的运行结果完全不同?
package _ELGamal;
import java.security.AlgorithmParameterGenerator;
import java.security.AlgorithmParameters;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.SecureRandom;
import java.security.Security;
import java.security.spec.InvalidParameterSpecException;
import javax.crypto.spec.DHParameterSpec;
import org.apache.commons.codec.binary.Base64;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.jce.spec.*;
public class ELGamal {
private static String ELGamal="xgqfrms";
private static String str1,str2;
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
MyELGamal();
}
public static void MyELGamal() throws Exception{
Security.addProvider(new BouncyCastleProvider());
AlgorithmParameterGenerator apg = AlgorithmParameterGenerator.getInstance(ELGamal);
apg.init(256);
AlgorithmParameters ap = apg.generateParameters();
DHParameterSpec dhps = (DHParameterSpec)ap.getParameterSpec(DHParameterSpec.class);
KeyPairGenerator kpg = KeyPairGenerator.getInstance(ELGamal);
kpg.initialize(dhps,new SecureRandom());
KeyPair kp = kpg.generateKeyPair();
PublicKey puk = kp.getPublic();
PrivateKey prk = kp.getPrivate();
str1 = "Public Key:"+Base64.encodeBase64String(puk.getEncoded());
str2 = "Private Key:"+Base64.encodeBase64String(prk.getEncoded());
System.out.println(str1);
System.out.println(str2);
}
}
error info:
Exception in thread "main" java.security.NoSuchAlgorithmException: xgqfrms AlgorithmParameterGenerator not available
at sun.security.jca.GetInstance.getInstance(Unknown Source)
at java.security.Security.getImpl(Unknown Source)
at java.security.AlgorithmParameterGenerator.getInstance(Unknown Source)
at _ELGamal.ELGamal.MyELGamal(ELGamal.java:33)
at _ELGamal.ELGamal.main(ELGamal.java:27)