本文整理汇总了Java中org.bouncycastle.crypto.params.GOST3410Parameters类的典型用法代码示例。如果您正苦于以下问题:Java GOST3410Parameters类的具体用法?Java GOST3410Parameters怎么用?Java GOST3410Parameters使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GOST3410Parameters类属于org.bouncycastle.crypto.params包,在下文中一共展示了GOST3410Parameters类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: generateKeyPair
import org.bouncycastle.crypto.params.GOST3410Parameters; //导入依赖的package包/类
public AsymmetricCipherKeyPair generateKeyPair()
{
BigInteger p, q, a, x, y;
GOST3410Parameters GOST3410Params = param.getParameters();
SecureRandom random = param.getRandom();
q = GOST3410Params.getQ();
p = GOST3410Params.getP();
a = GOST3410Params.getA();
do
{
x = new BigInteger(256, random);
}
while (x.equals(ZERO) || x.compareTo(q) >= 0);
//
// calculate the public key.
//
y = a.modPow(x, p);
return new AsymmetricCipherKeyPair(
new GOST3410PublicKeyParameters(y, GOST3410Params),
new GOST3410PrivateKeyParameters(x, GOST3410Params));
}
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:26,代码来源:GOST3410KeyPairGenerator.java
示例2: engineGenerateParameters
import org.bouncycastle.crypto.params.GOST3410Parameters; //导入依赖的package包/类
protected AlgorithmParameters engineGenerateParameters()
{
GOST3410ParametersGenerator pGen = new GOST3410ParametersGenerator();
if (random != null)
{
pGen.init(strength, 2, random);
}
else
{
pGen.init(strength, 2, new SecureRandom());
}
GOST3410Parameters p = pGen.generateParameters();
AlgorithmParameters params;
try
{
params = AlgorithmParameters.getInstance("GOST3410", BouncyCastleProvider.PROVIDER_NAME);
params.init(new GOST3410ParameterSpec(new GOST3410PublicKeyParameterSetSpec(p.getP(), p.getQ(), p.getA())));
}
catch (Exception e)
{
throw new RuntimeException(e.getMessage());
}
return params;
}
开发者ID:Appdome,项目名称:ipack,代码行数:30,代码来源:AlgorithmParameterGeneratorSpi.java
示例3: init
import org.bouncycastle.crypto.params.GOST3410Parameters; //导入依赖的package包/类
private void init(
GOST3410ParameterSpec gParams,
SecureRandom random)
{
GOST3410PublicKeyParameterSetSpec spec = gParams.getPublicKeyParameters();
param = new GOST3410KeyGenerationParameters(random, new GOST3410Parameters(spec.getP(), spec.getQ(), spec.getA()));
engine.init(param);
initialised = true;
gost3410Params = gParams;
}
开发者ID:Appdome,项目名称:ipack,代码行数:14,代码来源:KeyPairGeneratorSpi.java
示例4: generatePublicKeyParameter
import org.bouncycastle.crypto.params.GOST3410Parameters; //导入依赖的package包/类
static public AsymmetricKeyParameter generatePublicKeyParameter(
PublicKey key)
throws InvalidKeyException
{
if (key instanceof GOST3410PublicKey)
{
GOST3410PublicKey k = (GOST3410PublicKey)key;
GOST3410PublicKeyParameterSetSpec p = k.getParameters().getPublicKeyParameters();
return new GOST3410PublicKeyParameters(k.getY(),
new GOST3410Parameters(p.getP(), p.getQ(), p.getA()));
}
throw new InvalidKeyException("can't identify GOST3410 public key: " + key.getClass().getName());
}
开发者ID:Appdome,项目名称:ipack,代码行数:16,代码来源:GOST3410Util.java
示例5: generatePrivateKeyParameter
import org.bouncycastle.crypto.params.GOST3410Parameters; //导入依赖的package包/类
static public AsymmetricKeyParameter generatePrivateKeyParameter(
PrivateKey key)
throws InvalidKeyException
{
if (key instanceof GOST3410PrivateKey)
{
GOST3410PrivateKey k = (GOST3410PrivateKey)key;
GOST3410PublicKeyParameterSetSpec p = k.getParameters().getPublicKeyParameters();
return new GOST3410PrivateKeyParameters(k.getX(),
new GOST3410Parameters(p.getP(), p.getQ(), p.getA()));
}
throw new InvalidKeyException("can't identify GOST3410 private key.");
}
开发者ID:Appdome,项目名称:ipack,代码行数:16,代码来源:GOST3410Util.java
示例6: generateSignature
import org.bouncycastle.crypto.params.GOST3410Parameters; //导入依赖的package包/类
/**
* generate a signature for the given message using the key we were
* initialised with. For conventional GOST3410 the message should be a GOST3411
* hash of the message of interest.
*
* @param message the message that will be verified later.
*/
public BigInteger[] generateSignature(
byte[] message)
{
byte[] mRev = new byte[message.length]; // conversion is little-endian
for (int i = 0; i != mRev.length; i++)
{
mRev[i] = message[mRev.length - 1 - i];
}
BigInteger m = new BigInteger(1, mRev);
GOST3410Parameters params = key.getParameters();
BigInteger k;
do
{
k = new BigInteger(params.getQ().bitLength(), random);
}
while (k.compareTo(params.getQ()) >= 0);
BigInteger r = params.getA().modPow(k, params.getP()).mod(params.getQ());
BigInteger s = k.multiply(m).
add(((GOST3410PrivateKeyParameters)key).getX().multiply(r)).
mod(params.getQ());
BigInteger[] res = new BigInteger[2];
res[0] = r;
res[1] = s;
return res;
}
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:40,代码来源:GOST3410Signer.java
示例7: verifySignature
import org.bouncycastle.crypto.params.GOST3410Parameters; //导入依赖的package包/类
/**
* return true if the value r and s represent a GOST3410 signature for
* the passed in message for standard GOST3410 the message should be a
* GOST3411 hash of the real message to be verified.
*/
public boolean verifySignature(
byte[] message,
BigInteger r,
BigInteger s)
{
byte[] mRev = new byte[message.length]; // conversion is little-endian
for (int i = 0; i != mRev.length; i++)
{
mRev[i] = message[mRev.length - 1 - i];
}
BigInteger m = new BigInteger(1, mRev);
GOST3410Parameters params = key.getParameters();
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 v = m.modPow(params.getQ().subtract(new BigInteger("2")),params.getQ());
BigInteger z1 = s.multiply(v).mod(params.getQ());
BigInteger z2 = (params.getQ().subtract(r)).multiply(v).mod(params.getQ());
z1 = params.getA().modPow(z1, params.getP());
z2 = ((GOST3410PublicKeyParameters)key).getY().modPow(z2, params.getP());
BigInteger u = z1.multiply(z2).mod(params.getP()).mod(params.getQ());
return u.equals(r);
}
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:43,代码来源:GOST3410Signer.java
示例8: generateKeyPair
import org.bouncycastle.crypto.params.GOST3410Parameters; //导入依赖的package包/类
public AsymmetricCipherKeyPair generateKeyPair()
{
BigInteger p, q, a, x, y;
GOST3410Parameters GOST3410Params = param.getParameters();
SecureRandom random = param.getRandom();
q = GOST3410Params.getQ();
p = GOST3410Params.getP();
a = GOST3410Params.getA();
int minWeight = 64;
for (;;)
{
x = new BigInteger(256, random);
if (x.signum() < 1 || x.compareTo(q) >= 0)
{
continue;
}
if (WNafUtil.getNafWeight(x) < minWeight)
{
continue;
}
break;
}
//
// calculate the public key.
//
y = a.modPow(x, p);
return new AsymmetricCipherKeyPair(
new GOST3410PublicKeyParameters(y, GOST3410Params),
new GOST3410PrivateKeyParameters(x, GOST3410Params));
}
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:38,代码来源:GOST3410KeyPairGenerator.java
示例9: engineGenerateParameters
import org.bouncycastle.crypto.params.GOST3410Parameters; //导入依赖的package包/类
protected AlgorithmParameters engineGenerateParameters()
{
GOST3410ParametersGenerator pGen = new GOST3410ParametersGenerator();
if (random != null)
{
pGen.init(strength, 2, random);
}
else
{
pGen.init(strength, 2, new SecureRandom());
}
GOST3410Parameters p = pGen.generateParameters();
AlgorithmParameters params;
try
{
params = createParametersInstance("GOST3410");
params.init(new GOST3410ParameterSpec(new GOST3410PublicKeyParameterSetSpec(p.getP(), p.getQ(), p.getA())));
}
catch (Exception e)
{
throw new RuntimeException(e.getMessage());
}
return params;
}
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:30,代码来源:AlgorithmParameterGeneratorSpi.java
示例10: generateParameters
import org.bouncycastle.crypto.params.GOST3410Parameters; //导入依赖的package包/类
/**
* which generates the p , q and a values from the given parameters,
* returning the GOST3410Parameters object.
*/
public GOST3410Parameters generateParameters()
{
BigInteger [] pq = new BigInteger[2];
BigInteger q = null, p = null, a = null;
int x0, c;
long x0L, cL;
if (typeproc==1)
{
x0 = init_random.nextInt();
c = init_random.nextInt();
switch(size)
{
case 512:
procedure_A(x0, c, pq, 512);
break;
case 1024:
procedure_B(x0, c, pq);
break;
default:
throw new IllegalArgumentException("Ooops! key size 512 or 1024 bit.");
}
p = pq[0]; q = pq[1];
a = procedure_C(p, q);
//System.out.println("p:"+p.toString(16)+"\n"+"q:"+q.toString(16)+"\n"+"a:"+a.toString(16));
//System.out.println("p:"+p+"\n"+"q:"+q+"\n"+"a:"+a);
return new GOST3410Parameters(p, q, a, new GOST3410ValidationParameters(x0, c));
}
else
{
x0L = init_random.nextLong();
cL = init_random.nextLong();
switch(size)
{
case 512:
procedure_Aa(x0L, cL, pq, 512);
break;
case 1024:
procedure_Bb(x0L, cL, pq);
break;
default:
throw new IllegalStateException("Ooops! key size 512 or 1024 bit.");
}
p = pq[0]; q = pq[1];
a = procedure_C(p, q);
//System.out.println("p:"+p.toString(16)+"\n"+"q:"+q.toString(16)+"\n"+"a:"+a.toString(16));
//System.out.println("p:"+p+"\n"+"q:"+q+"\n"+"a:"+a);
return new GOST3410Parameters(p, q, a, new GOST3410ValidationParameters(x0L, cL));
}
}
开发者ID:Appdome,项目名称:ipack,代码行数:58,代码来源:GOST3410ParametersGenerator.java
示例11: perform
import org.bouncycastle.crypto.params.GOST3410Parameters; //导入依赖的package包/类
public TestResult perform()
{
BigInteger r = new BigInteger("a8790aabbd5a998ff524bad048ac69cd1faff2dab048265c8d60d1471c44a9ee",16);
BigInteger s = new BigInteger("30df5ba32ac77170b9632559bef7d37620017756dff3fea1088b4267db0944b8",16);
GOST3410ParametersGenerator pGen = new GOST3410ParametersGenerator();
pGen.init(1024, 1, 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");
}
}
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:58,代码来源:GOST3410Test.java
注:本文中的org.bouncycastle.crypto.params.GOST3410Parameters类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论