本文整理汇总了Java中org.bouncycastle.crypto.AsymmetricCipherKeyPair.getPrivate方法的典型用法代码示例。如果您正苦于以下问题:Java AsymmetricCipherKeyPair.getPrivate方法的具体用法?Java AsymmetricCipherKeyPair.getPrivate怎么用?Java AsymmetricCipherKeyPair.getPrivate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.crypto.AsymmetricCipherKeyPair
的用法示例。
在下文中一共展示了AsymmetricCipherKeyPair.getPrivate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateKeyPair
import org.bouncycastle.crypto.AsymmetricCipherKeyPair; //导入方法依赖的package包/类
public KeyPair generateKeyPair()
{
if (!initialised)
{
param = new RainbowKeyGenerationParameters(random, new RainbowParameters(new RainbowParameterSpec().getVi()));
engine.init(param);
initialised = true;
}
AsymmetricCipherKeyPair pair = engine.generateKeyPair();
RainbowPublicKeyParameters pub = (RainbowPublicKeyParameters)pair.getPublic();
RainbowPrivateKeyParameters priv = (RainbowPrivateKeyParameters)pair.getPrivate();
return new KeyPair(new BCRainbowPublicKey(pub),
new BCRainbowPrivateKey(priv));
}
示例2: generateClientKeyExchange
import org.bouncycastle.crypto.AsymmetricCipherKeyPair; //导入方法依赖的package包/类
public void generateClientKeyExchange(OutputStream output)
throws IOException
{
if (agreementCredentials != null)
{
return;
}
AsymmetricCipherKeyPair ecAgreeClientKeyPair = TlsECCUtils.generateECKeyPair(context.getSecureRandom(),
ecAgreeServerPublicKey.getParameters());
this.ecAgreeClientPrivateKey = (ECPrivateKeyParameters)ecAgreeClientKeyPair.getPrivate();
byte[] point = TlsECCUtils.serializeECPublicKey(serverECPointFormats,
(ECPublicKeyParameters)ecAgreeClientKeyPair.getPublic());
TlsUtils.writeOpaque8(point, output);
}
示例3: generateKeyPair
import org.bouncycastle.crypto.AsymmetricCipherKeyPair; //导入方法依赖的package包/类
public KeyPair generateKeyPair()
{
if (!initialised)
{
DSAParametersGenerator pGen = new DSAParametersGenerator();
pGen.init(strength, certainty, random);
param = new DSAKeyGenerationParameters(random, pGen.generateParameters());
engine.init(param);
initialised = true;
}
AsymmetricCipherKeyPair pair = engine.generateKeyPair();
DSAPublicKeyParameters pub = (DSAPublicKeyParameters)pair.getPublic();
DSAPrivateKeyParameters priv = (DSAPrivateKeyParameters)pair.getPrivate();
return new KeyPair(new BCDSAPublicKey(pub),
new BCDSAPrivateKey(priv));
}
示例4: ECDSAgeneratePublicAndPrivateKey
import org.bouncycastle.crypto.AsymmetricCipherKeyPair; //导入方法依赖的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;
}
示例5: generateKeyPair
import org.bouncycastle.crypto.AsymmetricCipherKeyPair; //导入方法依赖的package包/类
public KeyPair generateKeyPair()
{
if (!initialised)
{
init(new GOST3410ParameterSpec(CryptoProObjectIdentifiers.gostR3410_94_CryptoPro_A.getId()), new SecureRandom());
}
AsymmetricCipherKeyPair pair = engine.generateKeyPair();
GOST3410PublicKeyParameters pub = (GOST3410PublicKeyParameters)pair.getPublic();
GOST3410PrivateKeyParameters priv = (GOST3410PrivateKeyParameters)pair.getPrivate();
return new KeyPair(new BCGOST3410PublicKey(pub, gost3410Params), new BCGOST3410PrivateKey(priv, gost3410Params));
}
示例6: generateEphemeralClientKeyExchange
import org.bouncycastle.crypto.AsymmetricCipherKeyPair; //导入方法依赖的package包/类
public static DHPrivateKeyParameters generateEphemeralClientKeyExchange(SecureRandom random,
DHParameters dhParams, OutputStream output)
throws IOException
{
AsymmetricCipherKeyPair dhAgreeClientKeyPair = generateDHKeyPair(random, dhParams);
DHPrivateKeyParameters dhAgreeClientPrivateKey = (DHPrivateKeyParameters)dhAgreeClientKeyPair
.getPrivate();
BigInteger Yc = ((DHPublicKeyParameters)dhAgreeClientKeyPair.getPublic()).getY();
byte[] keData = BigIntegers.asUnsignedByteArray(Yc);
TlsUtils.writeOpaque16(keData, output);
return dhAgreeClientPrivateKey;
}
示例7: generateKeyPair
import org.bouncycastle.crypto.AsymmetricCipherKeyPair; //导入方法依赖的package包/类
public KeyPair generateKeyPair()
{
AsymmetricCipherKeyPair pair = engine.generateKeyPair();
RSAKeyParameters pub = (RSAKeyParameters)pair.getPublic();
RSAPrivateCrtKeyParameters priv = (RSAPrivateCrtKeyParameters)pair.getPrivate();
return new KeyPair(new BCRSAPublicKey(pub),
new BCRSAPrivateCrtKey(priv));
}
示例8: initEnc
import org.bouncycastle.crypto.AsymmetricCipherKeyPair; //导入方法依赖的package包/类
public ECPoint initEnc(SM2 sm2, ECPoint userKey) {
AsymmetricCipherKeyPair key = sm2.ecc_key_pair_generator.generateKeyPair();
ECPrivateKeyParameters ecpriv = (ECPrivateKeyParameters) key.getPrivate();
ECPublicKeyParameters ecpub = (ECPublicKeyParameters) key.getPublic();
BigInteger k = ecpriv.getD();
ECPoint c1 = ecpub.getQ();
this.p2 = userKey.multiply(k);
reset();
return c1;
}
示例9: createNew
import org.bouncycastle.crypto.AsymmetricCipherKeyPair; //导入方法依赖的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));
}
示例10: createNewPrivateKey
import org.bouncycastle.crypto.AsymmetricCipherKeyPair; //导入方法依赖的package包/类
@Override
public byte[] createNewPrivateKey() {
ECKeyPairGenerator generator = new ECKeyPairGenerator();
ECKeyGenerationParameters keygenParams = new ECKeyGenerationParameters(domain, secureRandom);
generator.init(keygenParams);
AsymmetricCipherKeyPair keypair = generator.generateKeyPair();
ECPrivateKeyParameters privParams = (ECPrivateKeyParameters) keypair.getPrivate();
return privParams.getD().toByteArray();
}
示例11: setEcDhParams
import org.bouncycastle.crypto.AsymmetricCipherKeyPair; //导入方法依赖的package包/类
protected void setEcDhParams() {
msg.prepareComputations();
generateNamedCurveList(msg);
generatePointFormatList(msg);
prepareCurveType(msg);
prepareNamedCurve(msg);
ECDomainParameters ecParams = generateEcParameters(msg);
AsymmetricCipherKeyPair keyPair = TlsECCUtils.generateECKeyPair(chooser.getContext().getBadSecureRandom(),
ecParams);
pubEcParams = (ECPublicKeyParameters) keyPair.getPublic();
privEcParams = (ECPrivateKeyParameters) keyPair.getPrivate();
}
示例12: generateEphemeralClientKeyExchange
import org.bouncycastle.crypto.AsymmetricCipherKeyPair; //导入方法依赖的package包/类
public static DHPrivateKeyParameters generateEphemeralClientKeyExchange(SecureRandom random, DHParameters dhParams,
OutputStream output) throws IOException
{
AsymmetricCipherKeyPair kp = generateDHKeyPair(random, dhParams);
DHPublicKeyParameters dhPublic = (DHPublicKeyParameters) kp.getPublic();
writeDHParameter(dhPublic.getY(), output);
return (DHPrivateKeyParameters) kp.getPrivate();
}
示例13: generateEphemeralClientKeyExchange
import org.bouncycastle.crypto.AsymmetricCipherKeyPair; //导入方法依赖的package包/类
public static ECPrivateKeyParameters generateEphemeralClientKeyExchange(SecureRandom random, short[] ecPointFormats,
ECDomainParameters ecParams, OutputStream output) throws IOException
{
AsymmetricCipherKeyPair kp = generateECKeyPair(random, ecParams);
ECPublicKeyParameters ecPublicKey = (ECPublicKeyParameters) kp.getPublic();
writeECPoint(ecPointFormats, ecPublicKey.getQ(), output);
return (ECPrivateKeyParameters) kp.getPrivate();
}
示例14: generateECDSAKey
import org.bouncycastle.crypto.AsymmetricCipherKeyPair; //导入方法依赖的package包/类
static private OneKey generateECDSAKey(String curveName, CBORObject curve) {
X9ECParameters p = NISTNamedCurves.getByName(curveName);
ECDomainParameters parameters = new ECDomainParameters(p.getCurve(), p.getG(), p.getN(), p.getH());
ECKeyPairGenerator pGen = new ECKeyPairGenerator();
ECKeyGenerationParameters genParam = new ECKeyGenerationParameters(parameters, null);
pGen.init(genParam);
AsymmetricCipherKeyPair p1 = pGen.generateKeyPair();
ECPublicKeyParameters keyPublic = (ECPublicKeyParameters) p1.getPublic();
ECPrivateKeyParameters keyPrivate = (ECPrivateKeyParameters) p1.getPrivate();
byte[] rgbX = keyPublic.getQ().normalize().getXCoord().getEncoded();
byte[] rgbY = keyPublic.getQ().normalize().getYCoord().getEncoded();
boolean signY = true;
byte[] rgbD = keyPrivate.getD().toByteArray();
OneKey key = new OneKey();
key.add(KeyKeys.KeyType, KeyKeys.KeyType_EC2);
key.add(KeyKeys.EC2_Curve, curve);
key.add(KeyKeys.EC2_X, CBORObject.FromObject(rgbX));
key.add(KeyKeys.EC2_Y, CBORObject.FromObject(rgbY));
key.add(KeyKeys.EC2_D, CBORObject.FromObject(rgbD));
return key;
}
示例15: perform
import org.bouncycastle.crypto.AsymmetricCipherKeyPair; //导入方法依赖的package包/类
public TestResult perform()
{
BigInteger r = new BigInteger("860d82c60e9502cd00c0e9e1f6563feafec304801974d745c5e02079946f729e",16);
BigInteger s = new BigInteger("7ef49264ef022801aaa03033cd97915235fbab4c823ed936b0f360c22114688a",16);
GOST3410ParametersGenerator pGen = new GOST3410ParametersGenerator();
pGen.init(1024, 2, init_random);
GOST3410Parameters params = pGen.generateParameters();
if (!pValue.equals(params.getP()) || !qValue.equals(params.getQ()))
{
return new SimpleTestResult(false, getName() + ": p or q wrong");
}
GOST3410KeyPairGenerator GOST3410KeyGen = new GOST3410KeyPairGenerator();
GOST3410KeyGenerationParameters genParam = new GOST3410KeyGenerationParameters(keyRandom, params);
GOST3410KeyGen.init(genParam);
AsymmetricCipherKeyPair pair = GOST3410KeyGen.generateKeyPair();
ParametersWithRandom param = new ParametersWithRandom(pair.getPrivate(), random);
GOST3410Signer GOST3410 = new GOST3410Signer();
GOST3410.init(true, param);
BigInteger[] sig = GOST3410.generateSignature(hashmessage);
if (!r.equals(sig[0]))
{
return new SimpleTestResult(false, getName()
+ ": r component wrong." + Strings.lineSeparator()
+ " expecting: " + r.toString(16) + Strings.lineSeparator()
+ " got : " + sig[0].toString(16));
}
if (!s.equals(sig[1]))
{
return new SimpleTestResult(false, getName()
+ ": s component wrong." + Strings.lineSeparator()
+ " expecting: " + s.toString(16) + Strings.lineSeparator()
+ " got : " + sig[1].toString(16));
}
GOST3410.init(false, pair.getPublic());
if (GOST3410.verifySignature(hashmessage, sig[0], sig[1]))
{
return new SimpleTestResult(true, getName() + ": Okay");
}
else
{
return new SimpleTestResult(false, getName() + ": verification fails");
}
}