本文整理汇总了Java中org.bouncycastle.crypto.AsymmetricCipherKeyPair类的典型用法代码示例。如果您正苦于以下问题:Java AsymmetricCipherKeyPair类的具体用法?Java AsymmetricCipherKeyPair怎么用?Java AsymmetricCipherKeyPair使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AsymmetricCipherKeyPair类属于org.bouncycastle.crypto包,在下文中一共展示了AsymmetricCipherKeyPair类的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: generateKeyPairSingleThread
import org.bouncycastle.crypto.AsymmetricCipherKeyPair; //导入依赖的package包/类
/**
* Generates a new signature key pair. Runs in a single thread.
*
* @return a key pair
*/
public AsymmetricCipherKeyPair generateKeyPairSingleThread()
{
List<NTRUSigningPrivateKeyParameters.Basis> basises = new ArrayList<NTRUSigningPrivateKeyParameters.Basis>();
NTRUSigningPublicKeyParameters pub = null;
for (int k = params.B; k >= 0; k--)
{
NTRUSigningPrivateKeyParameters.Basis basis = generateBoundedBasis();
basises.add(basis);
if (k == 0)
{
pub = new NTRUSigningPublicKeyParameters(basis.h, params.getSigningParameters());
}
}
NTRUSigningPrivateKeyParameters priv = new NTRUSigningPrivateKeyParameters(basises, pub);
return new AsymmetricCipherKeyPair(pub, priv);
}
示例3: genKeyPair
import org.bouncycastle.crypto.AsymmetricCipherKeyPair; //导入依赖的package包/类
/**
* This function generates a Rainbow key pair.
*
* @return the generated key pair
*/
public AsymmetricCipherKeyPair genKeyPair()
{
RainbowPrivateKeyParameters privKey;
RainbowPublicKeyParameters pubKey;
if (!initialized)
{
initializeDefault();
}
/* choose all coefficients at random */
keygen();
/* now marshall them to PrivateKey */
privKey = new RainbowPrivateKeyParameters(A1inv, b1, A2inv, b2, vi, layers);
/* marshall to PublicKey */
pubKey = new RainbowPublicKeyParameters(vi[vi.length - 1] - vi[0], pub_quadratic, pub_singular, pub_scalar);
return new AsymmetricCipherKeyPair(pubKey, privKey);
}
示例4: 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);
}
示例5: 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));
}
示例6: generateKeyPair
import org.bouncycastle.crypto.AsymmetricCipherKeyPair; //导入依赖的package包/类
public AsymmetricCipherKeyPair generateKeyPair()
{
BigInteger p, q, g, x, y;
DSAParameters dsaParams = param.getParameters();
SecureRandom random = param.getRandom();
q = dsaParams.getQ();
p = dsaParams.getP();
g = dsaParams.getG();
do
{
x = new BigInteger(160, random);
}
while (x.equals(ZERO) || x.compareTo(q) >= 0);
//
// calculate the public key.
//
y = g.modPow(x, p);
return new AsymmetricCipherKeyPair(
new DSAPublicKeyParameters(y, dsaParams),
new DSAPrivateKeyParameters(x, dsaParams));
}
示例7: generateKeyPair
import org.bouncycastle.crypto.AsymmetricCipherKeyPair; //导入依赖的package包/类
public AsymmetricCipherKeyPair generateKeyPair()
{
BigInteger p, g, x, y;
int qLength = param.getStrength() - 1;
DHParameters dhParams = param.getParameters();
p = dhParams.getP();
g = dhParams.getG();
//
// calculate the private key
//
x = new BigInteger(qLength, param.getRandom());
//
// calculate the public key.
//
y = g.modPow(x, p);
return new AsymmetricCipherKeyPair(
new DHPublicKeyParameters(y, dhParams),
new DHPrivateKeyParameters(x, dhParams));
}
示例8: generateKeyPair
import org.bouncycastle.crypto.AsymmetricCipherKeyPair; //导入依赖的package包/类
/**
* Given the domain parameters this routine generates an EC key
* pair in accordance with X9.62 section 5.2.1 pages 26, 27.
*/
public AsymmetricCipherKeyPair generateKeyPair()
{
BigInteger n = params.getN();
int nBitLength = n.bitLength();
BigInteger d;
do
{
d = new BigInteger(nBitLength, random);
}
while (d.equals(ZERO) || (d.compareTo(n) >= 0));
ECPoint Q = params.getG().multiply(d);
return new AsymmetricCipherKeyPair(
new ECPublicKeyParameters(Q, params),
new ECPrivateKeyParameters(d, params));
}
示例9: generateKeyPair
import org.bouncycastle.crypto.AsymmetricCipherKeyPair; //导入依赖的package包/类
public AsymmetricCipherKeyPair generateKeyPair()
{
BigInteger p, g, x, y;
int qLength = param.getStrength() - 1;
DHParameters dhParams = param.getParameters();
p = dhParams.getP();
g = dhParams.getG();
//
// calculate the private key
//
x = new BigInteger(qLength, param.getRandom());
//
// calculate the public key.
//
y = g.modPow(x, p);
return new AsymmetricCipherKeyPair(
new DHPublicKeyParameters(y, dhParams),
new DHPrivateKeyParameters(x, dhParams));
}
示例10: makeV1Certificate
import org.bouncycastle.crypto.AsymmetricCipherKeyPair; //导入依赖的package包/类
public static X509CertificateHolder makeV1Certificate(AsymmetricCipherKeyPair subKP, String _subDN, AsymmetricCipherKeyPair issKP, String _issDN)
throws IOException, OperatorCreationException
{
RSAKeyParameters lwPubKey = (RSAKeyParameters)subKP.getPublic();
X509v1CertificateBuilder v1CertGen = new X509v1CertificateBuilder(
new X500Name(_issDN),
allocateSerialNumber(),
new Date(System.currentTimeMillis()),
new Date(System.currentTimeMillis() + (1000L * 60 * 60 * 24 * 100)),
new X500Name(_subDN),
new SubjectPublicKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE), new RSAPublicKey(lwPubKey.getModulus(), lwPubKey.getExponent()))
);
AlgorithmIdentifier sigAlgId = new DefaultSignatureAlgorithmIdentifierFinder().find("SHA1WithRSAEncryption");
AlgorithmIdentifier digAlgId = new DefaultDigestAlgorithmIdentifierFinder().find(sigAlgId);
ContentSigner sigGen = new BcRSAContentSignerBuilder(sigAlgId, digAlgId).build((AsymmetricKeyParameter)issKP.getPrivate());
return v1CertGen.build(sigGen);
}
示例11: makeCertificate
import org.bouncycastle.crypto.AsymmetricCipherKeyPair; //导入依赖的package包/类
public static X509CertificateHolder makeCertificate(AsymmetricCipherKeyPair subKP, String _subDN, AsymmetricCipherKeyPair issKP, String _issDN, boolean _ca)
throws IOException, OperatorCreationException
{
RSAKeyParameters lwPubKey = (RSAKeyParameters)subKP.getPublic();
X509v3CertificateBuilder v3CertGen = new X509v3CertificateBuilder(
new X500Name(_issDN),
allocateSerialNumber(),
new Date(System.currentTimeMillis()),
new Date(System.currentTimeMillis() + (1000L * 60 * 60 * 24 * 100)),
new X500Name(_subDN),
new SubjectPublicKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE), new RSAPublicKey(lwPubKey.getModulus(), lwPubKey.getExponent()))
);
AlgorithmIdentifier sigAlgId = new DefaultSignatureAlgorithmIdentifierFinder().find("SHA1WithRSAEncryption");
AlgorithmIdentifier digAlgId = new DefaultDigestAlgorithmIdentifierFinder().find(sigAlgId);
ContentSigner sigGen = new BcRSAContentSignerBuilder(sigAlgId, digAlgId).build((AsymmetricKeyParameter)issKP.getPrivate());
v3CertGen.addExtension(
X509Extension.basicConstraints,
false,
new BasicConstraints(_ca));
return v3CertGen.build(sigGen);
}
示例12: 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;
}
示例13: generateKeyPair
import org.bouncycastle.crypto.AsymmetricCipherKeyPair; //导入依赖的package包/类
/**
* Generates a new signature key pair. Starts <code>B+1</code> threads.
*
* @return a key pair
*/
public AsymmetricCipherKeyPair generateKeyPair()
{
NTRUSigningPublicKeyParameters pub = null;
ExecutorService executor = Executors.newCachedThreadPool();
List<Future<NTRUSigningPrivateKeyParameters.Basis>> bases = new ArrayList<Future<NTRUSigningPrivateKeyParameters.Basis>>();
for (int k = params.B; k >= 0; k--)
{
bases.add(executor.submit(new BasisGenerationTask()));
}
executor.shutdown();
List<NTRUSigningPrivateKeyParameters.Basis> basises = new ArrayList<NTRUSigningPrivateKeyParameters.Basis>();
for (int k = params.B; k >= 0; k--)
{
Future<NTRUSigningPrivateKeyParameters.Basis> basis = bases.get(k);
try
{
basises.add(basis.get());
if (k == params.B)
{
pub = new NTRUSigningPublicKeyParameters(basis.get().h, params.getSigningParameters());
}
}
catch (Exception e)
{
throw new IllegalStateException(e);
}
}
NTRUSigningPrivateKeyParameters priv = new NTRUSigningPrivateKeyParameters(basises, pub);
AsymmetricCipherKeyPair kp = new AsymmetricCipherKeyPair(pub, priv);
return kp;
}
示例14: generateServerKeyExchange
import org.bouncycastle.crypto.AsymmetricCipherKeyPair; //导入依赖的package包/类
public byte[] generateServerKeyExchange()
throws IOException
{
if (this.dhParameters == null)
{
throw new TlsFatalAlert(AlertDescription.internal_error);
}
ByteArrayOutputStream buf = new ByteArrayOutputStream();
DHKeyPairGenerator kpg = new DHKeyPairGenerator();
kpg.init(new DHKeyGenerationParameters(context.getSecureRandom(), this.dhParameters));
AsymmetricCipherKeyPair kp = kpg.generateKeyPair();
BigInteger Ys = ((DHPublicKeyParameters)kp.getPublic()).getY();
TlsDHUtils.writeDHParameter(dhParameters.getP(), buf);
TlsDHUtils.writeDHParameter(dhParameters.getG(), buf);
TlsDHUtils.writeDHParameter(Ys, buf);
byte[] digestInput = buf.toByteArray();
Digest d = new CombinedHash();
SecurityParameters securityParameters = context.getSecurityParameters();
d.update(securityParameters.clientRandom, 0, securityParameters.clientRandom.length);
d.update(securityParameters.serverRandom, 0, securityParameters.serverRandom.length);
d.update(digestInput, 0, digestInput.length);
byte[] hash = new byte[d.getDigestSize()];
d.doFinal(hash, 0);
byte[] sigBytes = serverCredentials.generateCertificateSignature(hash);
/*
* TODO RFC 5246 4.7. digitally-signed element needs SignatureAndHashAlgorithm prepended from TLS 1.2
*/
TlsUtils.writeOpaque16(sigBytes, buf);
return buf.toByteArray();
}
示例15: generateDHKeyPair
import org.bouncycastle.crypto.AsymmetricCipherKeyPair; //导入依赖的package包/类
public static AsymmetricCipherKeyPair generateDHKeyPair(SecureRandom random,
DHParameters dhParams)
{
DHBasicKeyPairGenerator dhGen = new DHBasicKeyPairGenerator();
dhGen.init(new DHKeyGenerationParameters(random, dhParams));
return dhGen.generateKeyPair();
}