本文整理汇总了Java中org.bouncycastle.util.BigIntegers类的典型用法代码示例。如果您正苦于以下问题:Java BigIntegers类的具体用法?Java BigIntegers怎么用?Java BigIntegers使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BigIntegers类属于org.bouncycastle.util包,在下文中一共展示了BigIntegers类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSM2Z
import org.bouncycastle.util.BigIntegers; //导入依赖的package包/类
public static byte[] getSM2Z(byte[] userID, ASN1ObjectIdentifier curveOid,
BigInteger pubPointX, BigInteger pubPointY) {
SM3Digest digest = new SM3Digest();
addUserID(digest, userID);
X9ECParameters ecParams = GMNamedCurves.getByOID(curveOid);
addFieldElement(digest, ecParams.getCurve().getA());
addFieldElement(digest, ecParams.getCurve().getB());
addFieldElement(digest, ecParams.getG().getAffineXCoord());
addFieldElement(digest, ecParams.getG().getAffineYCoord());
int fieldSize = (ecParams.getCurve().getFieldSize() + 7) / 8;
byte[] bytes = BigIntegers.asUnsignedByteArray(fieldSize, pubPointX);
digest.update(bytes, 0, fieldSize);
bytes = BigIntegers.asUnsignedByteArray(fieldSize, pubPointY);
digest.update(bytes, 0, fieldSize);
byte[] result = new byte[digest.getDigestSize()];
digest.doFinal(result, 0);
return result;
}
示例2: calculateZeroKnowledgeProof
import org.bouncycastle.util.BigIntegers; //导入依赖的package包/类
/**
* Calculate a zero knowledge proof of x using Schnorr's signature.
* The returned array has two elements {g^v, r = v-x*h} for x.
*/
public static BigInteger[] calculateZeroKnowledgeProof(
BigInteger p,
BigInteger q,
BigInteger g,
BigInteger gx,
BigInteger x,
String participantId,
Digest digest,
SecureRandom random)
{
BigInteger[] zeroKnowledgeProof = new BigInteger[2];
/* Generate a random v, and compute g^v */
BigInteger vMin = ZERO;
BigInteger vMax = q.subtract(ONE);
BigInteger v = BigIntegers.createRandomInRange(vMin, vMax, random);
BigInteger gv = g.modPow(v, p);
BigInteger h = calculateHashForZeroKnowledgeProof(g, gv, gx, participantId, digest); // h
zeroKnowledgeProof[0] = gv;
zeroKnowledgeProof[1] = v.subtract(x.multiply(h)).mod(q); // r = v-x*h
return zeroKnowledgeProof;
}
示例3: calculatePrivate
import org.bouncycastle.util.BigIntegers; //导入依赖的package包/类
BigInteger calculatePrivate(DHParameters dhParams, SecureRandom random)
{
BigInteger p = dhParams.getP();
int limit = dhParams.getL();
if (limit != 0)
{
return new BigInteger(limit, random).setBit(limit - 1);
}
BigInteger min = TWO;
int m = dhParams.getM();
if (m != 0)
{
min = ONE.shiftLeft(m - 1);
}
BigInteger max = p.subtract(TWO);
BigInteger q = dhParams.getQ();
if (q != null)
{
max = q.subtract(TWO);
}
return BigIntegers.createRandomInRange(min, max, random);
}
示例4: ECPrivateKeyStructure
import org.bouncycastle.util.BigIntegers; //导入依赖的package包/类
public ECPrivateKeyStructure(
BigInteger key,
DERBitString publicKey,
ASN1Encodable parameters)
{
byte[] bytes = BigIntegers.asUnsignedByteArray(key);
ASN1EncodableVector v = new ASN1EncodableVector();
v.add(new ASN1Integer(1));
v.add(new DEROctetString(bytes));
if (parameters != null)
{
v.add(new DERTaggedObject(true, 0, parameters));
}
if (publicKey != null)
{
v.add(new DERTaggedObject(true, 1, publicKey));
}
seq = new DERSequence(v);
}
示例5: isFinalSolutionCorrect
import org.bouncycastle.util.BigIntegers; //导入依赖的package包/类
@Override
public boolean isFinalSolutionCorrect(BigInteger guessedSecret) {
// BigInteger correct = new
// BigInteger("25091756309879652045519159642875354611257005804552159157");
// if (correct.compareTo(guessedSecret) == 0) {
// return true;
// } else {
// return false;
// }
computer.setSecret(guessedSecret);
try {
Point p = computer.mul(checkPoint);
byte[] pms = BigIntegers.asUnsignedByteArray(curve.getKeyBits() / 8, p.getX());
return Arrays.equals(checkPMS, pms);
} catch (DivisionException ex) {
LOGGER.debug(ex);
return false;
}
}
示例6: generatePremasterSecret
import org.bouncycastle.util.BigIntegers; //导入依赖的package包/类
public byte[] generatePremasterSecret() throws IOException
{
try
{
BigInteger S = srpServer != null
? srpServer.calculateSecret(srpPeerCredentials)
: srpClient.calculateSecret(srpPeerCredentials);
// TODO Check if this needs to be a fixed size
return BigIntegers.asUnsignedByteArray(S);
}
catch (CryptoException e)
{
throw new TlsFatalAlert(AlertDescription.illegal_parameter, e);
}
}
示例7: encrypt
import org.bouncycastle.util.BigIntegers; //导入依赖的package包/类
/**
* Generate and encapsulate a random session key.
*
* @param out the output buffer for the encapsulated key.
* @param outOff the offset for the output buffer.
* @param keyLen the length of the random session key.
* @return the random session key.
*/
public CipherParameters encrypt(byte[] out, int outOff, int keyLen)
throws IllegalArgumentException
{
if (key.isPrivate())
{
throw new IllegalArgumentException("Public key required for encryption");
}
BigInteger n = key.getModulus();
BigInteger e = key.getExponent();
// Generate the ephemeral random and encode it
BigInteger r = BigIntegers.createRandomInRange(ZERO, n.subtract(ONE), rnd);
// Encrypt the random and encode it
BigInteger c = r.modPow(e, n);
byte[] C = BigIntegers.asUnsignedByteArray((n.bitLength() + 7) / 8, c);
System.arraycopy(C, 0, out, outOff, C.length);
return generateKey(n, r, keyLen);
}
示例8: generatePrivateKey
import org.bouncycastle.util.BigIntegers; //导入依赖的package包/类
private static BigInteger generatePrivateKey(BigInteger q, SecureRandom random)
{
// B.1.2 Key Pair Generation by Testing Candidates
int minWeight = q.bitLength() >>> 2;
for (;;)
{
// TODO Prefer this method? (change test cases that used fixed random)
// B.1.1 Key Pair Generation Using Extra Random Bits
// BigInteger x = new BigInteger(q.bitLength() + 64, random).mod(q.subtract(ONE)).add(ONE);
BigInteger x = BigIntegers.createRandomInRange(ONE, q.subtract(ONE), random);
if (WNafUtil.getNafWeight(x) >= minWeight)
{
return x;
}
}
}
示例9: selectGenerator
import org.bouncycastle.util.BigIntegers; //导入依赖的package包/类
static BigInteger selectGenerator(BigInteger p, SecureRandom random)
{
BigInteger pMinusTwo = p.subtract(TWO);
BigInteger g;
/*
* RFC 2631 2.2.1.2 (and see: Handbook of Applied Cryptography 4.81)
*/
do
{
BigInteger h = BigIntegers.createRandomInRange(TWO, pMinusTwo, random);
g = h.modPow(TWO, p);
}
while (g.equals(ONE));
return g;
}
示例10: ECPrivateKey
import org.bouncycastle.util.BigIntegers; //导入依赖的package包/类
public ECPrivateKey(
int orderBitLength,
BigInteger key,
DERBitString publicKey,
ASN1Encodable parameters)
{
byte[] bytes = BigIntegers.asUnsignedByteArray((orderBitLength + 7) / 8, key);
ASN1EncodableVector v = new ASN1EncodableVector();
v.add(new ASN1Integer(1));
v.add(new DEROctetString(bytes));
if (parameters != null)
{
v.add(new DERTaggedObject(true, 0, parameters));
}
if (publicKey != null)
{
v.add(new DERTaggedObject(true, 1, publicKey));
}
seq = new DERSequence(v);
}
示例11: performTest
import org.bouncycastle.util.BigIntegers; //导入依赖的package包/类
public void performTest()
throws Exception
{
BigInteger pSubOne = DHStandardGroups.rfc3526_2048.getP().subtract(ONE);
for (int i = 0; i < 10; ++i)
{
BigInteger message = BigIntegers.createRandomInRange(ONE, pSubOne, RND);
BigInteger m1 = encDecTest(message);
BigInteger m2 = labelledEncDecTest(message, "myRandomLabel");
BigInteger m3 = encDecEncodingTest(message);
BigInteger m4 = labelledEncDecEncodingTest(message, "myOtherCoolLabel");
if (!message.equals(m1) || !message.equals(m2) || !message.equals(m3) || !message.equals(m4))
{
fail("decrypted message != original message");
}
}
}
示例12: findBetaValues
import org.bouncycastle.util.BigIntegers; //导入依赖的package包/类
private static ECFieldElement[] findBetaValues(ECCurve c)
{
BigInteger q = c.getField().getCharacteristic();
BigInteger e = q.divide(ECConstants.THREE);
// Search for a random value that generates a non-trival cube root of 1
SecureRandom random = new SecureRandom();
BigInteger b;
do
{
BigInteger r = BigIntegers.createRandomInRange(ECConstants.TWO, q.subtract(ECConstants.TWO), random);
b = r.modPow(e, q);
}
while (b.equals(ECConstants.ONE));
ECFieldElement beta = c.fromBigInteger(b);
return new ECFieldElement[]{ beta, beta.square() };
}
示例13: generateSignature
import org.bouncycastle.util.BigIntegers; //导入依赖的package包/类
/**
* generate a signature for the loaded message using the key we were
* initialised with.
*/
public byte[] generateSignature()
throws CryptoException
{
createSignatureBlock();
BigInteger t = new BigInteger(1, cipher.processBlock(block, 0, block.length));
BigInteger nSubT = kParam.getModulus().subtract(t);
clearBlock(block);
BigInteger v = kParam.getModulus().shiftRight(2);
if (t.compareTo(nSubT) > 0)
{
return BigIntegers.asUnsignedByteArray((kParam.getModulus().bitLength() + 7) / 8, nSubT);
}
else
{
return BigIntegers.asUnsignedByteArray((kParam.getModulus().bitLength() + 7) / 8, t);
}
}
示例14: decodeFPPoint
import org.bouncycastle.util.BigIntegers; //导入依赖的package包/类
@Deprecated
public static ECPoint decodeFPPoint(ECCurve curve, byte[] data) {
// Patched org.bouncycastle.math.ec.ECCurve#decodePoint code.
int expectedLength = (curve.getFieldSize() + 7) / 8;
if (expectedLength != data.length) {
throw new IllegalArgumentException("incorrect data length for compact encoding");
}
BigInteger X = BigIntegers.fromUnsignedByteArray(data, 0, expectedLength);
ECPoint p = decompressFPPoint(curve, X);
if (!satisfiesCofactor(curve, p)) {
throw new IllegalArgumentException("invalid point");
}
return p;
}
示例15: importKey
import org.bouncycastle.util.BigIntegers; //导入依赖的package包/类
@Override
public Optional<ECPublicKey> importKey(String curveName, byte[] data) {
int fieldLength = ECAssistant.fieldLength(curveName);
if (fieldLength(data.length) != fieldLength) {
logger.warn("-- importKey() - bad data length: {} curve: {} data:0x{}",
data.length, curveName, Hex.toHexString(data));
}
if (!checkType(data[0])) {
logger.warn("-- importKey() - bad data type: 0x{}", Integer.toHexString(data[0]));
}
BigInteger x = BigIntegers.fromUnsignedByteArray(data, 1, fieldLength);
BigInteger y = BigIntegers.fromUnsignedByteArray(data, 1 + fieldLength, fieldLength);
return ECKeyFactories.publicKeyFactory()
.createECPublicKey(x, y, curveName);
}