本文整理汇总了Java中org.bouncycastle.crypto.params.ECKeyGenerationParameters类的典型用法代码示例。如果您正苦于以下问题:Java ECKeyGenerationParameters类的具体用法?Java ECKeyGenerationParameters怎么用?Java ECKeyGenerationParameters使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ECKeyGenerationParameters类属于org.bouncycastle.crypto.params包,在下文中一共展示了ECKeyGenerationParameters类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initialize
import org.bouncycastle.crypto.params.ECKeyGenerationParameters; //导入依赖的package包/类
public void initialize(
int strength,
SecureRandom random)
{
this.strength = strength;
this.random = random;
this.ecParams = (ECParameterSpec)ecParameters.get(new Integer(strength));
if (ecParams != null)
{
param = new ECKeyGenerationParameters(new ECDomainParameters(ecParams.getCurve(), ecParams.getG(), ecParams.getN()), random);
engine.init(param);
initialised = true;
}
}
示例2: ECDSAgeneratePublicAndPrivateKey
import org.bouncycastle.crypto.params.ECKeyGenerationParameters; //导入依赖的package包/类
/*************
* This method will create the ECDSA public and private key which is returned in a Byte array of Byte arrays, index 0 is the private key and
* index 1 of the array will return the ECDSA public key
*
* -Wisdom: This guy didn't check whether the returned Private Key would be more than 32.
* @return
*/
private byte[][] ECDSAgeneratePublicAndPrivateKey(){
int length = 0;
byte[][] keys;
do{
ECKeyPairGenerator gen = new ECKeyPairGenerator();
SecureRandom secureRandom = new SecureRandom();
X9ECParameters secnamecurves = SECNamedCurves.getByName("secp256k1");
ECDomainParameters ecParams = new ECDomainParameters(secnamecurves.getCurve(), secnamecurves.getG(), secnamecurves.getN(), secnamecurves.getH());
ECKeyGenerationParameters keyGenParam = new ECKeyGenerationParameters(ecParams, secureRandom);
gen.init(keyGenParam);
AsymmetricCipherKeyPair kp = gen.generateKeyPair();
ECPrivateKeyParameters privatekey = (ECPrivateKeyParameters)kp.getPrivate();
ECPoint dd = secnamecurves.getG().multiply(privatekey.getD());
byte[] publickey=new byte[65];
System.arraycopy(dd.getY().toBigInteger().toByteArray(), 0, publickey, 64-dd.getY().toBigInteger().toByteArray().length+1, dd.getY().toBigInteger().toByteArray().length);
System.arraycopy(dd.getX().toBigInteger().toByteArray(), 0, publickey, 32-dd.getX().toBigInteger().toByteArray().length+1, dd.getX().toBigInteger().toByteArray().length);
publickey[0]=4;
length = privatekey.getD().toByteArray().length;
keys = new byte[][]{privatekey.getD().toByteArray(),publickey};
}while(length != 32);
return keys;
}
示例3: curveTest
import org.bouncycastle.crypto.params.ECKeyGenerationParameters; //导入依赖的package包/类
@Test
public void curveTest() {
final X9ECParameters curve = NISTNamedCurves.getByName("P-384");
final ECDomainParameters domainParameters = new ECDomainParameters(
curve.getCurve(), curve.getG(), curve.getN());
final SecureRandom random = new SecureRandom();
final ECKeyPairGenerator gen = new ECKeyPairGenerator();
gen.init(new ECKeyGenerationParameters(domainParameters, random));
final AsymmetricCipherKeyPair senderPair = gen.generateKeyPair();
final AsymmetricCipherKeyPair receiverPair = gen.generateKeyPair();
final ECDHBasicAgreement senderAgreement = new ECDHBasicAgreement();
senderAgreement.init(senderPair.getPrivate());
final BigInteger senderResult = senderAgreement.calculateAgreement(
receiverPair.getPublic());
final ECDHBasicAgreement receiverAgreement = new ECDHBasicAgreement();
receiverAgreement.init(receiverPair.getPrivate());
final BigInteger receiverResult = receiverAgreement.calculateAgreement(
senderPair.getPublic());
assertEquals(senderResult, receiverResult);
//System.out.println(receiverResult);
}
示例4: curveTest
import org.bouncycastle.crypto.params.ECKeyGenerationParameters; //导入依赖的package包/类
@Test
public void curveTest() {
final X9ECParameters curve = NISTNamedCurves.getByName("P-384");
final ECDomainParameters domainParameters = new ECDomainParameters(
curve.getCurve(), curve.getG(), curve.getN());
final SecureRandom random = new SecureRandom();
final ECKeyPairGenerator gen = new ECKeyPairGenerator();
gen.init(new ECKeyGenerationParameters(domainParameters, random));
final AsymmetricCipherKeyPair senderPair = gen.generateKeyPair();
final ECDSASigner signer = new ECDSASigner();
signer.init(true, senderPair.getPrivate());
final byte[] message = "The magic words are squeamish ossifrage".getBytes(
Constants.ASCII);
final SHA384Digest digester = new SHA384Digest();
digester.update(message, 0, message.length);
final byte[] digest = new byte[digester.getDigestSize()];
digester.doFinal(digest, 0);
final BigInteger[] signature = signer.generateSignature(digest);
final ECDSASigner verifier = new ECDSASigner();
verifier.init(false, senderPair.getPublic());
assertTrue(verifier.verifySignature(digest, signature[0], signature[1]));
}
示例5: doTestOnPeers
import org.bouncycastle.crypto.params.ECKeyGenerationParameters; //导入依赖的package包/类
private void doTestOnPeers(int numberOfPeers)
{
X9ECParameters params = SECNamedCurves.getByName("secp256r1");
ECKeyPairGenerator kpGen = new ECKeyPairGenerator();
ECDomainParameters domainParams = new ECDomainParameters(params.getCurve(), params.getG(), params.getN(), params.getH(), params.getSeed());
kpGen.init(new ECKeyGenerationParameters(domainParams, new SecureRandom()));
AsymmetricCipherKeyPair[] kps = new AsymmetricCipherKeyPair[numberOfPeers];
// Generate Private Keys - normally this would be done by each
// individual server. For this example we will just create them in an
// array.
for (int i = 0; i < kps.length; i++)
{
kps[i] = kpGen.generateKeyPair();
}
doTest(domainParams, kps, numberOfPeers - 1, true, 1);
doTest(domainParams, kps, numberOfPeers - 2, true, 1);
doTest(domainParams, kps, numberOfPeers - 2, true, 1, 3);
doTest(domainParams, kps, numberOfPeers - 1, false, 1, 3);
}
示例6: testECDSAKeyGenTest
import org.bouncycastle.crypto.params.ECKeyGenerationParameters; //导入依赖的package包/类
/**
* key generation test
*/
private void testECDSAKeyGenTest()
{
SecureRandom random = new SecureRandom();
ECCurve.Fp curve = new ECCurve.Fp(
new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839"), // q
new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a
new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16)); // b
ECDomainParameters params = new ECDomainParameters(
curve,
curve.decodePoint(Hex.decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G
new BigInteger("883423532389192164791648750360308884807550341691627752275345424702807307")); // n
ECKeyPairGenerator pGen = new ECKeyPairGenerator();
ECKeyGenerationParameters genParam = new ECKeyGenerationParameters(
params,
random);
pGen.init(genParam);
AsymmetricCipherKeyPair pair = pGen.generateKeyPair();
ParametersWithRandom param = new ParametersWithRandom(pair.getPrivate(), random);
ECDSASigner ecdsa = new ECDSASigner();
ecdsa.init(true, param);
byte[] message = new BigInteger("968236873715988614170569073515315707566766479517").toByteArray();
BigInteger[] sig = ecdsa.generateSignature(message);
ecdsa.init(false, pair.getPublic());
if (!ecdsa.verifySignature(message, sig[0], sig[1]))
{
fail("signature fails");
}
}
示例7: initialize
import org.bouncycastle.crypto.params.ECKeyGenerationParameters; //导入依赖的package包/类
public void initialize(
int strength,
SecureRandom random)
{
this.strength = strength;
this.random = random;
this.ecParams = (ECParameterSpec)ecParameters.get(Integers.valueOf(strength));
if (ecParams != null)
{
param = new ECKeyGenerationParameters(new ECDomainParameters(ecParams.getCurve(), ecParams.getG(), ecParams.getN()), random);
engine.init(param);
initialised = true;
}
else
{
throw new InvalidParameterException("unknown key size.");
}
}
示例8: initialize
import org.bouncycastle.crypto.params.ECKeyGenerationParameters; //导入依赖的package包/类
public void initialize(
int strength,
SecureRandom random)
{
this.strength = strength;
this.random = random;
if (ecParams != null)
{
param = new ECKeyGenerationParameters(new ECDomainParameters(ecParams.getCurve(), ecParams.getG(), ecParams.getN()), random);
engine.init(param);
initialised = true;
}
else
{
throw new InvalidParameterException("unknown key size.");
}
}
示例9: generateECKeyPair
import org.bouncycastle.crypto.params.ECKeyGenerationParameters; //导入依赖的package包/类
public static AsymmetricCipherKeyPair generateECKeyPair(SecureRandom random, ECDomainParameters ecParams)
{
ECKeyPairGenerator keyPairGenerator = new ECKeyPairGenerator();
ECKeyGenerationParameters keyGenerationParameters = new ECKeyGenerationParameters(ecParams, random);
keyPairGenerator.init(keyGenerationParameters);
return keyPairGenerator.generateKeyPair();
}
示例10: init
import org.bouncycastle.crypto.params.ECKeyGenerationParameters; //导入依赖的package包/类
public void init(
KeyGenerationParameters param)
{
ECKeyGenerationParameters ecP = (ECKeyGenerationParameters)param;
this.random = ecP.getRandom();
this.params = ecP.getDomainParameters();
}
示例11: createNew
import org.bouncycastle.crypto.params.ECKeyGenerationParameters; //导入依赖的package包/类
/**
* Create a new PrivateKey using the platform provided secure random source.
*
* @param compressed set to false if you relly want legacy format
* @return new PrivateKey
*/
public static PrivateKey createNew(boolean compressed) {
ECKeyPairGenerator generator = new ECKeyPairGenerator();
ECKeyGenerationParameters keygenParams = new ECKeyGenerationParameters(domain, secureRandom);
generator.init(keygenParams);
AsymmetricCipherKeyPair keypair = generator.generateKeyPair();
ECPrivateKeyParameters privParams = (ECPrivateKeyParameters) keypair.getPrivate();
ECPublicKeyParameters pubParams = (ECPublicKeyParameters) keypair.getPublic();
return new PrivateKey(privParams.getD(), compressed, pubParams.getQ().getEncoded(compressed));
}
示例12: generateECPublicKey
import org.bouncycastle.crypto.params.ECKeyGenerationParameters; //导入依赖的package包/类
public static AsymmetricCipherKeyPair generateECPublicKey() {
// Should we also generate random curves?
X9ECParameters ecp = SECNamedCurves.getByName(getRandomCurveName());
ECKeyPairGenerator keygen = new ECKeyPairGenerator();
ECDomainParameters domainParams = new ECDomainParameters(ecp.getCurve(), ecp.getG(), ecp.getN(), ecp.getH(),
ecp.getSeed());
keygen.init(new ECKeyGenerationParameters(domainParams, RandomHelper.getBadSecureRandom()));
return keygen.generateKeyPair();
}
示例13: init
import org.bouncycastle.crypto.params.ECKeyGenerationParameters; //导入依赖的package包/类
public void init(
KeyGenerationParameters param)
{
ECKeyGenerationParameters ecP = (ECKeyGenerationParameters)param;
this.random = ecP.getRandom();
this.params = ecP.getDomainParameters();
if (this.random == null)
{
this.random = new SecureRandom();
}
}
示例14: testECMQVRandom
import org.bouncycastle.crypto.params.ECKeyGenerationParameters; //导入依赖的package包/类
private void testECMQVRandom()
{
SecureRandom random = new SecureRandom();
BigInteger n = new BigInteger("883423532389192164791648750360308884807550341691627752275345424702807307");
ECCurve.Fp curve = new ECCurve.Fp(
new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839"), // q
new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a
new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16), // b
n, ECConstants.ONE);
ECDomainParameters parameters = new ECDomainParameters(
curve,
curve.decodePoint(Hex.decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G
n);
ECKeyPairGenerator pGen = new ECKeyPairGenerator();
pGen.init(new ECKeyGenerationParameters(parameters, random));
// Pre-established key pairs
AsymmetricCipherKeyPair U1 = pGen.generateKeyPair();
AsymmetricCipherKeyPair V1 = pGen.generateKeyPair();
// Ephemeral key pairs
AsymmetricCipherKeyPair U2 = pGen.generateKeyPair();
AsymmetricCipherKeyPair V2 = pGen.generateKeyPair();
BigInteger x = calculateAgreement(U1, U2, V1, V2);
if (x == null)
{
fail("MQV Test Vector (random) agreement failed");
}
}
示例15: performTest
import org.bouncycastle.crypto.params.ECKeyGenerationParameters; //导入依赖的package包/类
public void performTest()
throws Exception
{
doStaticTest(null);
doStaticTest(TWOFISH_IV);
doShortTest(null);
BigInteger n = new BigInteger("6277101735386680763835789423176059013767194773182842284081");
ECCurve.Fp curve = new ECCurve.Fp(
new BigInteger("6277101735386680763835789423207666416083908700390324961279"), // q
new BigInteger("fffffffffffffffffffffffffffffffefffffffffffffffc", 16), // a
new BigInteger("64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1", 16), // b
n, ECConstants.ONE);
ECDomainParameters params = new ECDomainParameters(
curve,
curve.decodePoint(Hex.decode("03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012")), // G
n);
ECKeyPairGenerator eGen = new ECKeyPairGenerator();
KeyGenerationParameters gParam = new ECKeyGenerationParameters(params, new SecureRandom());
eGen.init(gParam);
AsymmetricCipherKeyPair p1 = eGen.generateKeyPair();
AsymmetricCipherKeyPair p2 = eGen.generateKeyPair();
doTest(p1, p2);
doEphemeralTest(null, false);
doEphemeralTest(null, true);
doEphemeralTest(TWOFISH_IV, false);
doEphemeralTest(TWOFISH_IV, true);
}