本文整理汇总了Java中org.bouncycastle.crypto.params.DSAPrivateKeyParameters类的典型用法代码示例。如果您正苦于以下问题:Java DSAPrivateKeyParameters类的具体用法?Java DSAPrivateKeyParameters怎么用?Java DSAPrivateKeyParameters使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DSAPrivateKeyParameters类属于org.bouncycastle.crypto.params包,在下文中一共展示了DSAPrivateKeyParameters类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import org.bouncycastle.crypto.params.DSAPrivateKeyParameters; //导入依赖的package包/类
public void init(
boolean forSigning,
CipherParameters param)
{
if (forSigning)
{
if (param instanceof ParametersWithRandom)
{
ParametersWithRandom rParam = (ParametersWithRandom)param;
this.random = rParam.getRandom();
this.key = (DSAPrivateKeyParameters)rParam.getParameters();
}
else
{
this.random = new SecureRandom();
this.key = (DSAPrivateKeyParameters)param;
}
}
else
{
this.key = (DSAPublicKeyParameters)param;
}
}
示例2: generateKeyPair
import org.bouncycastle.crypto.params.DSAPrivateKeyParameters; //导入依赖的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));
}
示例3: generateKeyPair
import org.bouncycastle.crypto.params.DSAPrivateKeyParameters; //导入依赖的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));
}
示例4: generateKeyPair
import org.bouncycastle.crypto.params.DSAPrivateKeyParameters; //导入依赖的package包/类
public AsymmetricCipherKeyPair generateKeyPair()
{
DSAParameters dsaParams = param.getParameters();
BigInteger x = generatePrivateKey(dsaParams.getQ(), param.getRandom());
BigInteger y = calculatePublicKey(dsaParams.getP(), dsaParams.getG(), x);
return new AsymmetricCipherKeyPair(
new DSAPublicKeyParameters(y, dsaParams),
new DSAPrivateKeyParameters(x, dsaParams));
}
示例5: generatePrivateKeyParameter
import org.bouncycastle.crypto.params.DSAPrivateKeyParameters; //导入依赖的package包/类
static public AsymmetricKeyParameter generatePrivateKeyParameter(
PrivateKey key)
throws InvalidKeyException
{
if (key instanceof DSAPrivateKey)
{
DSAPrivateKey k = (DSAPrivateKey)key;
return new DSAPrivateKeyParameters(k.getX(),
new DSAParameters(k.getParams().getP(), k.getParams().getQ(), k.getParams().getG()));
}
throw new InvalidKeyException("can't identify DSA private key.");
}
示例6: init
import org.bouncycastle.crypto.params.DSAPrivateKeyParameters; //导入依赖的package包/类
public void init(
boolean forSigning,
CipherParameters param)
{
SecureRandom providedRandom = null;
if (forSigning)
{
if (param instanceof ParametersWithRandom)
{
ParametersWithRandom rParam = (ParametersWithRandom)param;
this.key = (DSAPrivateKeyParameters)rParam.getParameters();
providedRandom = rParam.getRandom();
}
else
{
this.key = (DSAPrivateKeyParameters)param;
}
}
else
{
this.key = (DSAPublicKeyParameters)param;
}
this.random = initSecureRandom(forSigning && !kCalculator.isDeterministic(), providedRandom);
}
示例7: generateSignature
import org.bouncycastle.crypto.params.DSAPrivateKeyParameters; //导入依赖的package包/类
/**
* generate a signature for the given message using the key we were
* initialised with. For conventional DSA the message should be a SHA-1
* hash of the message of interest.
*
* @param message the message that will be verified later.
*/
public BigInteger[] generateSignature(
byte[] message)
{
DSAParameters params = key.getParameters();
BigInteger q = params.getQ();
BigInteger m = calculateE(q, message);
BigInteger x = ((DSAPrivateKeyParameters)key).getX();
if (kCalculator.isDeterministic())
{
kCalculator.init(q, x, message);
}
else
{
kCalculator.init(q, random);
}
BigInteger k = kCalculator.nextK();
BigInteger r = params.getG().modPow(k, params.getP()).mod(q);
k = k.modInverse(q).multiply(m.add(x.multiply(r)));
BigInteger s = k.mod(q);
return new BigInteger[]{ r, s };
}
示例8: initSign
import org.bouncycastle.crypto.params.DSAPrivateKeyParameters; //导入依赖的package包/类
/** {@inheritDoc} */
public void initSign() {
if (signKey == null) {
throw new IllegalStateException(
"Sign key must be set prior to initialization.");
}
final DSAPrivateKey privKey = (DSAPrivateKey) signKey;
final DSAParams params = privKey.getParams();
final DSAPrivateKeyParameters bcParams = new DSAPrivateKeyParameters(
privKey.getX(), new DSAParameters(params.getP(), params.getQ(),
params.getG()));
init(true, bcParams);
}
示例9: generateSignature
import org.bouncycastle.crypto.params.DSAPrivateKeyParameters; //导入依赖的package包/类
/**
* generate a signature for the given message using the key we were
* initialised with. For conventional DSA the message should be a SHA-1
* hash of the message of interest.
*
* @param message the message that will be verified later.
*/
public BigInteger[] generateSignature(
byte[] message)
{
DSAParameters params = key.getParameters();
BigInteger m = calculateE(params.getQ(), message);
if (kCalculator.isDeterministic())
{
kCalculator.init(params.getQ(), ((DSAPrivateKeyParameters)key).getX(), message);
}
else
{
kCalculator.init(params.getQ(), random);
}
BigInteger k = kCalculator.nextK();
BigInteger r = params.getG().modPow(k, params.getP()).mod(params.getQ());
k = k.modInverse(params.getQ()).multiply(
m.add(((DSAPrivateKeyParameters)key).getX().multiply(r)));
BigInteger s = k.mod(params.getQ());
BigInteger[] res = new BigInteger[2];
res[0] = r;
res[1] = s;
return res;
}
示例10: generateSignature
import org.bouncycastle.crypto.params.DSAPrivateKeyParameters; //导入依赖的package包/类
/**
* generate a signature for the given message using the key we were
* initialised with. For conventional DSA the message should be a SHA-1
* hash of the message of interest.
*
* @param message the message that will be verified later.
*/
public BigInteger[] generateSignature(
byte[] message)
{
DSAParameters params = key.getParameters();
BigInteger m = calculateE(params.getQ(), message);
BigInteger k;
int qBitLength = params.getQ().bitLength();
do
{
k = new BigInteger(qBitLength, random);
}
while (k.compareTo(params.getQ()) >= 0);
BigInteger r = params.getG().modPow(k, params.getP()).mod(params.getQ());
k = k.modInverse(params.getQ()).multiply(
m.add(((DSAPrivateKeyParameters)key).getX().multiply(r)));
BigInteger s = k.mod(params.getQ());
BigInteger[] res = new BigInteger[2];
res[0] = r;
res[1] = s;
return res;
}
示例11: generates1024bitKeys
import org.bouncycastle.crypto.params.DSAPrivateKeyParameters; //导入依赖的package包/类
@Test
public void generates1024bitKeys() throws Exception {
final AsymmetricCipherKeyPair pair = DsaKeyGenerator.dsa1024().generate(random);
assertThat(pair.getPrivate())
.isInstanceOf(DSAPrivateKeyParameters.class);
final DSAPrivateKeyParameters privateKeys = (DSAPrivateKeyParameters) pair.getPrivate();
assertThat(privateKeys.getParameters().getP().toByteArray().length)
.isEqualTo(129);
}
示例12: generates2048bitKeys
import org.bouncycastle.crypto.params.DSAPrivateKeyParameters; //导入依赖的package包/类
@Test
public void generates2048bitKeys() throws Exception {
final AsymmetricCipherKeyPair pair = DsaKeyGenerator.dsa2048().generate(random);
assertThat(pair.getPrivate())
.isInstanceOf(DSAPrivateKeyParameters.class);
final DSAPrivateKeyParameters privateKeys = (DSAPrivateKeyParameters) pair.getPrivate();
assertThat(privateKeys.getParameters().getP().toByteArray().length)
.isIn(257);
}
示例13: generates3072bitKeys
import org.bouncycastle.crypto.params.DSAPrivateKeyParameters; //导入依赖的package包/类
@Test
public void generates3072bitKeys() throws Exception {
final AsymmetricCipherKeyPair pair = DsaKeyGenerator.dsa3072().generate(random);
assertThat(pair.getPrivate())
.isInstanceOf(DSAPrivateKeyParameters.class);
final DSAPrivateKeyParameters privateKeys = (DSAPrivateKeyParameters) pair.getPrivate();
assertThat(privateKeys.getParameters().getP().toByteArray().length)
.isIn(385);
}
示例14: enableClientAuthentication
import org.bouncycastle.crypto.params.DSAPrivateKeyParameters; //导入依赖的package包/类
public void enableClientAuthentication(Certificate clientCertificate,
AsymmetricKeyParameter clientPrivateKey)
{
if (clientCertificate == null)
{
throw new IllegalArgumentException("'clientCertificate' cannot be null");
}
if (clientCertificate.certs.length == 0)
{
throw new IllegalArgumentException("'clientCertificate' cannot be empty");
}
if (clientPrivateKey == null)
{
throw new IllegalArgumentException("'clientPrivateKey' cannot be null");
}
if (!clientPrivateKey.isPrivate())
{
throw new IllegalArgumentException("'clientPrivateKey' must be private");
}
if (clientPrivateKey instanceof RSAKeyParameters)
{
clientSigner = new TlsRSASigner();
}
else if (clientPrivateKey instanceof DSAPrivateKeyParameters)
{
clientSigner = new TlsDSSSigner();
}
else
{
throw new IllegalArgumentException("'clientPrivateKey' type not supported: "
+ clientPrivateKey.getClass().getName());
}
this.clientCert = clientCertificate;
this.clientPrivateKey = clientPrivateKey;
}
示例15: JDKDSAPrivateKey
import org.bouncycastle.crypto.params.DSAPrivateKeyParameters; //导入依赖的package包/类
JDKDSAPrivateKey(
DSAPrivateKeyParameters params)
{
this.x = params.getX();
this.dsaSpec = new DSAParameterSpec(params.getParameters().getP(), params.getParameters().getQ(), params.getParameters().getG());
}