本文整理汇总了Java中org.bouncycastle.crypto.params.DSAParameters类的典型用法代码示例。如果您正苦于以下问题:Java DSAParameters类的具体用法?Java DSAParameters怎么用?Java DSAParameters使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DSAParameters类属于org.bouncycastle.crypto.params包,在下文中一共展示了DSAParameters类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: initialize
import org.bouncycastle.crypto.params.DSAParameters; //导入依赖的package包/类
public void initialize(
AlgorithmParameterSpec params,
SecureRandom random)
throws InvalidAlgorithmParameterException
{
if (!(params instanceof DSAParameterSpec))
{
throw new InvalidAlgorithmParameterException("parameter object not a DSAParameterSpec");
}
DSAParameterSpec dsaParams = (DSAParameterSpec)params;
param = new DSAKeyGenerationParameters(random, new DSAParameters(dsaParams.getP(), dsaParams.getQ(), dsaParams.getG()));
engine.init(param);
initialised = true;
}
开发者ID:Appdome,项目名称:ipack,代码行数:17,代码来源:KeyPairGeneratorSpi.java
示例2: generateKeyPair
import org.bouncycastle.crypto.params.DSAParameters; //导入依赖的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));
}
开发者ID:thangbn,项目名称:Direct-File-Downloader,代码行数:26,代码来源:DSAKeyPairGenerator.java
示例3: createAsymmetricCipherKeyPairGenerator
import org.bouncycastle.crypto.params.DSAParameters; //导入依赖的package包/类
@Override
public AsymmetricCipherKeyPairGenerator createAsymmetricCipherKeyPairGenerator(final boolean initWithDefaults) {
final DSAKeyPairGenerator generator = new DSAKeyPairGenerator();
if (initWithDefaults) {
/*
* How certain do we want to be that the chosen primes are really primes.
* <p>
* The higher this number, the more tests are done to make sure they are primes (and not composites).
* <p>
* See: <a href="http://crypto.stackexchange.com/questions/3114/what-is-the-correct-value-for-certainty-in-rsa-key-pair-generation">What is the correct value for “certainty” in RSA key pair generation?</a>
* and
* <a href="http://crypto.stackexchange.com/questions/3126/does-a-high-exponent-compensate-for-a-low-degree-of-certainty?lq=1">Does a high exponent compensate for a low degree of certainty?</a>
*/
final int certainty = 12;
final SecureRandom random = new SecureRandom();
final DSAParametersGenerator pGen = new DSAParametersGenerator();
pGen.init(4096, certainty, random);
final DSAParameters dsaParameters = pGen.generateParameters();
final DSAKeyGenerationParameters dsaKeyGenerationParameters = new DSAKeyGenerationParameters(random, dsaParameters);
generator.init(dsaKeyGenerationParameters);
}
return generator;
}
开发者ID:subshare,项目名称:subshare,代码行数:27,代码来源:DSAKeyPairGeneratorFactory.java
示例4: createDsaKeyGenerationParameters
import org.bouncycastle.crypto.params.DSAParameters; //导入依赖的package包/类
private DSAKeyGenerationParameters createDsaKeyGenerationParameters(final CreatePgpKeyParam createPgpKeyParam) {
/*
* How certain do we want to be that the chosen primes are really primes.
* <p>
* The higher this number, the more tests are done to make sure they are primes (and not composites).
* <p>
* See: <a href="http://crypto.stackexchange.com/questions/3114/what-is-the-correct-value-for-certainty-in-rsa-key-pair-generation">What is the correct value for “certainty” in RSA key pair generation?</a>
* and
* <a href="http://crypto.stackexchange.com/questions/3126/does-a-high-exponent-compensate-for-a-low-degree-of-certainty?lq=1">Does a high exponent compensate for a low degree of certainty?</a>
*/
final int certainty = 12;
final SecureRandom random = getSecureRandom();
final DSAParametersGenerator pGen = new DSAParametersGenerator();
pGen.init(createPgpKeyParam.getStrength(), certainty, random);
final DSAParameters dsaParameters = pGen.generateParameters();
return new DSAKeyGenerationParameters(random, dsaParameters);
}
开发者ID:subshare,项目名称:subshare,代码行数:20,代码来源:BcWithLocalGnuPgPgp.java
示例5: verifySignature
import org.bouncycastle.crypto.params.DSAParameters; //导入依赖的package包/类
/**
* return true if the value r and s represent a DSA signature for
* the passed in message for standard DSA the message should be a
* SHA-1 hash of the real message to be verified.
*/
public boolean verifySignature(
byte[] message,
BigInteger r,
BigInteger s)
{
DSAParameters params = key.getParameters();
BigInteger m = calculateE(params.getQ(), message);
BigInteger zero = BigInteger.valueOf(0);
if (zero.compareTo(r) >= 0 || params.getQ().compareTo(r) <= 0)
{
return false;
}
if (zero.compareTo(s) >= 0 || params.getQ().compareTo(s) <= 0)
{
return false;
}
BigInteger w = s.modInverse(params.getQ());
BigInteger u1 = m.multiply(w).mod(params.getQ());
BigInteger u2 = r.multiply(w).mod(params.getQ());
u1 = params.getG().modPow(u1, params.getP());
u2 = ((DSAPublicKeyParameters)key).getY().modPow(u2, params.getP());
BigInteger v = u1.multiply(u2).mod(params.getP()).mod(params.getQ());
return v.equals(r);
}
开发者ID:Appdome,项目名称:ipack,代码行数:37,代码来源:DSASigner.java
示例6: generateParameters
import org.bouncycastle.crypto.params.DSAParameters; //导入依赖的package包/类
/**
* which generates the p and g values from the given parameters,
* returning the DSAParameters object.
* <p>
* Note: can take a while...
*/
public DSAParameters generateParameters()
{
return (use186_3)
? generateParameters_FIPS186_3()
: generateParameters_FIPS186_2();
}
开发者ID:Appdome,项目名称:ipack,代码行数:13,代码来源:DSAParametersGenerator.java
示例7: generateKeyPair
import org.bouncycastle.crypto.params.DSAParameters; //导入依赖的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));
}
开发者ID:Appdome,项目名称:ipack,代码行数:12,代码来源:DSAKeyPairGenerator.java
示例8: generatePublicKeyParameter
import org.bouncycastle.crypto.params.DSAParameters; //导入依赖的package包/类
static public AsymmetricKeyParameter generatePublicKeyParameter(
PublicKey key)
throws InvalidKeyException
{
if (key instanceof DSAPublicKey)
{
DSAPublicKey k = (DSAPublicKey)key;
return new DSAPublicKeyParameters(k.getY(),
new DSAParameters(k.getParams().getP(), k.getParams().getQ(), k.getParams().getG()));
}
throw new InvalidKeyException("can't identify DSA public key: " + key.getClass().getName());
}
开发者ID:Appdome,项目名称:ipack,代码行数:15,代码来源:DSAUtil.java
示例9: generatePrivateKeyParameter
import org.bouncycastle.crypto.params.DSAParameters; //导入依赖的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.");
}
开发者ID:Appdome,项目名称:ipack,代码行数:15,代码来源:DSAUtil.java
示例10: generateDSAKeypair
import org.bouncycastle.crypto.params.DSAParameters; //导入依赖的package包/类
public static KeyPair generateDSAKeypair(DSAParameters dsaParams, SecureRandom random)
throws NoSuchAlgorithmException, NoSuchProviderException,
InvalidAlgorithmParameterException {
DSAParameterSpec dsaParamSpec = new DSAParameterSpec(dsaParams.getP(), dsaParams.getQ(),
dsaParams.getG());
KeyPairGenerator kpGen = getKeyPairGenerator("DSA");
synchronized (kpGen) {
kpGen.initialize(dsaParamSpec, random);
return kpGen.generateKeyPair();
}
}
开发者ID:xipki,项目名称:xitk,代码行数:12,代码来源:KeyUtil.java
示例11: getNewDSAParameterSpec
import org.bouncycastle.crypto.params.DSAParameters; //导入依赖的package包/类
public static DSAParameterSpec getNewDSAParameterSpec(int plength, int qlength,
SecureRandom random) {
final int certainty = 80;
SecureRandom tmpRandom = (random == null) ? new SecureRandom() : random;
DSAParametersGenerator paramGen = new DSAParametersGenerator(new SHA512Digest());
DSAParameterGenerationParameters genParams = new DSAParameterGenerationParameters(
plength, qlength, certainty, tmpRandom);
paramGen.init(genParams);
DSAParameters dsaParams = paramGen.generateParameters();
return new DSAParameterSpec(dsaParams.getP(), dsaParams.getQ(), dsaParams.getG());
}
开发者ID:xipki,项目名称:xitk,代码行数:12,代码来源:DSAParameterCache.java
示例12: generateDSAKeypair0
import org.bouncycastle.crypto.params.DSAParameters; //导入依赖的package包/类
@Override
// CHECKSTYLE:OFF
protected P11Identity generateDSAKeypair0(BigInteger p, BigInteger q, BigInteger g,
String label, P11NewKeyControl control) throws P11TokenException {
// CHECKSTYLE:ON
DSAParameters dsaParams = new DSAParameters(p, q, g);
KeyPair keypair;
try {
keypair = KeyUtil.generateDSAKeypair(dsaParams, random);
} catch (NoSuchAlgorithmException | NoSuchProviderException
| InvalidAlgorithmParameterException ex) {
throw new P11TokenException(ex.getMessage(), ex);
}
return saveP11Entity(keypair, label);
}
开发者ID:xipki,项目名称:xitk,代码行数:16,代码来源:EmulatorP11Slot.java
示例13: engineGenerateParameters
import org.bouncycastle.crypto.params.DSAParameters; //导入依赖的package包/类
protected AlgorithmParameters engineGenerateParameters()
{
DSAParametersGenerator pGen = new DSAParametersGenerator();
if ( random != null )
{
pGen.init(strength, 20, random);
}
else
{
pGen.init(strength, 20, new SecureRandom());
}
DSAParameters p = pGen.generateParameters();
AlgorithmParameters params;
try
{
params = AlgorithmParameters.getInstance("DSA", BouncyCastleProvider.PROVIDER_NAME);
params.init(new DSAParameterSpec(p.getP(), p.getQ(), p.getG()));
}
catch (Exception e)
{
throw new RuntimeException(e.getMessage());
}
return params;
}
开发者ID:thangbn,项目名称:Direct-File-Downloader,代码行数:30,代码来源:JDKAlgorithmParameterGenerator.java
示例14: generateSignature
import org.bouncycastle.crypto.params.DSAParameters; //导入依赖的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 };
}
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:35,代码来源:DSASigner.java
示例15: verifySignature
import org.bouncycastle.crypto.params.DSAParameters; //导入依赖的package包/类
/**
* return true if the value r and s represent a DSA signature for
* the passed in message for standard DSA the message should be a
* SHA-1 hash of the real message to be verified.
*/
public boolean verifySignature(
byte[] message,
BigInteger r,
BigInteger s)
{
DSAParameters params = key.getParameters();
BigInteger q = params.getQ();
BigInteger m = calculateE(q, message);
BigInteger zero = BigInteger.valueOf(0);
if (zero.compareTo(r) >= 0 || q.compareTo(r) <= 0)
{
return false;
}
if (zero.compareTo(s) >= 0 || q.compareTo(s) <= 0)
{
return false;
}
BigInteger w = s.modInverse(q);
BigInteger u1 = m.multiply(w).mod(q);
BigInteger u2 = r.multiply(w).mod(q);
BigInteger p = params.getP();
u1 = params.getG().modPow(u1, p);
u2 = ((DSAPublicKeyParameters)key).getY().modPow(u2, p);
BigInteger v = u1.multiply(u2).mod(p).mod(q);
return v.equals(r);
}
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:39,代码来源:DSASigner.java
示例16: initSign
import org.bouncycastle.crypto.params.DSAParameters; //导入依赖的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);
}
开发者ID:shivam091,项目名称:Java-Security,代码行数:15,代码来源:DSASignature.java
示例17: initVerify
import org.bouncycastle.crypto.params.DSAParameters; //导入依赖的package包/类
/** {@inheritDoc} */
public void initVerify() {
if (verifyKey == null) {
throw new IllegalStateException(
"Verify key must be set prior to initialization.");
}
final DSAPublicKey pubKey = (DSAPublicKey) verifyKey;
final DSAParams params = pubKey.getParams();
final DSAPublicKeyParameters bcParams = new DSAPublicKeyParameters(
pubKey.getY(), new DSAParameters(params.getP(), params.getQ(),
params.getG()));
init(false, bcParams);
}
开发者ID:shivam091,项目名称:Java-Security,代码行数:15,代码来源:DSASignature.java
示例18: generateSignature
import org.bouncycastle.crypto.params.DSAParameters; //导入依赖的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;
}
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:39,代码来源:DSASigner.java
注:本文中的org.bouncycastle.crypto.params.DSAParameters类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论