本文整理汇总了Java中org.bouncycastle.util.BigIntegers.asUnsignedByteArray方法的典型用法代码示例。如果您正苦于以下问题:Java BigIntegers.asUnsignedByteArray方法的具体用法?Java BigIntegers.asUnsignedByteArray怎么用?Java BigIntegers.asUnsignedByteArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.util.BigIntegers
的用法示例。
在下文中一共展示了BigIntegers.asUnsignedByteArray方法的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: 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);
}
示例3: 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);
}
示例4: 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;
}
}
示例5: 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);
}
示例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: 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);
}
}
示例8: calculateDHBasicAgreement
import org.bouncycastle.util.BigIntegers; //导入方法依赖的package包/类
public static byte[] calculateDHBasicAgreement(DHPublicKeyParameters publicKey,
DHPrivateKeyParameters privateKey)
{
DHBasicAgreement basicAgreement = new DHBasicAgreement();
basicAgreement.init(privateKey);
BigInteger agreementValue = basicAgreement.calculateAgreement(publicKey);
/*
* RFC 5246 8.1.2. Leading bytes of Z that contain all zero bits are stripped before it is
* used as the pre_master_secret.
*/
return BigIntegers.asUnsignedByteArray(agreementValue);
}
示例9: generateEphemeralClientKeyExchange
import org.bouncycastle.util.BigIntegers; //导入方法依赖的package包/类
public static DHPrivateKeyParameters generateEphemeralClientKeyExchange(SecureRandom random,
DHParameters dhParams, OutputStream output)
throws IOException
{
AsymmetricCipherKeyPair dhAgreeClientKeyPair = generateDHKeyPair(random, dhParams);
DHPrivateKeyParameters dhAgreeClientPrivateKey = (DHPrivateKeyParameters)dhAgreeClientKeyPair
.getPrivate();
BigInteger Yc = ((DHPublicKeyParameters)dhAgreeClientKeyPair.getPublic()).getY();
byte[] keData = BigIntegers.asUnsignedByteArray(Yc);
TlsUtils.writeOpaque16(keData, output);
return dhAgreeClientPrivateKey;
}
示例10: calculateECDHBasicAgreement
import org.bouncycastle.util.BigIntegers; //导入方法依赖的package包/类
public static byte[] calculateECDHBasicAgreement(ECPublicKeyParameters publicKey, ECPrivateKeyParameters privateKey)
{
ECDHBasicAgreement basicAgreement = new ECDHBasicAgreement();
basicAgreement.init(privateKey);
BigInteger agreementValue = basicAgreement.calculateAgreement(publicKey);
/*
* RFC 4492 5.10. Note that this octet string (Z in IEEE 1363 terminology) as output by
* FE2OSP, the Field Element to Octet String Conversion Primitive, has constant length for
* any given field; leading zeros found in this octet string MUST NOT be truncated.
*/
return BigIntegers.asUnsignedByteArray(basicAgreement.getFieldSize(), agreementValue);
}
示例11: generateAgreement
import org.bouncycastle.util.BigIntegers; //导入方法依赖的package包/类
public byte[] generateAgreement(AsymmetricKeyParameter peerPublicKey)
{
basicAgreement.init(privateKey);
BigInteger agreementValue = basicAgreement.calculateAgreement(peerPublicKey);
if (truncateAgreement)
{
return BigIntegers.asUnsignedByteArray(agreementValue);
}
return BigIntegers.asUnsignedByteArray(basicAgreement.getFieldSize(), agreementValue);
}
示例12: generateClientKeyExchange
import org.bouncycastle.util.BigIntegers; //导入方法依赖的package包/类
public void generateClientKeyExchange(OutputStream output)
throws IOException
{
byte[] keData = BigIntegers.asUnsignedByteArray(srpClient.generateClientCredentials(s, this.identity,
this.password));
TlsUtils.writeOpaque16(keData, output);
}
示例13: generatePremasterSecret
import org.bouncycastle.util.BigIntegers; //导入方法依赖的package包/类
public byte[] generatePremasterSecret()
throws IOException
{
try
{
// TODO Check if this needs to be a fixed size
return BigIntegers.asUnsignedByteArray(srpClient.calculateSecret(B));
}
catch (CryptoException e)
{
throw new TlsFatalAlert(AlertDescription.illegal_parameter);
}
}
示例14: setNonce
import org.bouncycastle.util.BigIntegers; //导入方法依赖的package包/类
public void setNonce(BigInteger nonce)
{
// RFC 3029, 9.1: The DVCS MAY modify the fields
// 'dvcs', 'requester', 'dataLocations', and 'nonce' of the ReqInfo structure
// RFC 3029, 9.1: The only modification
// allowed to a 'nonce' is the inclusion of a new field if it was not
// present, or to concatenate other data to the end (right) of an
// existing value.
if (initialInfo != null)
{
if (initialInfo.getNonce() == null)
{
this.nonce = nonce;
}
else
{
byte[] initialBytes = initialInfo.getNonce().toByteArray();
byte[] newBytes = BigIntegers.asUnsignedByteArray(nonce);
byte[] nonceBytes = new byte[initialBytes.length + newBytes.length];
System.arraycopy(initialBytes, 0, nonceBytes, 0, initialBytes.length);
System.arraycopy(newBytes, 0, nonceBytes, initialBytes.length, newBytes.length);
this.nonce = new BigInteger(nonceBytes);
}
}
this.nonce = nonce;
}
示例15: getPadded
import org.bouncycastle.util.BigIntegers; //导入方法依赖的package包/类
private static byte[] getPadded(BigInteger n, int length)
{
byte[] bs = BigIntegers.asUnsignedByteArray(n);
if (bs.length < length)
{
byte[] tmp = new byte[length];
System.arraycopy(bs, 0, tmp, length - bs.length, bs.length);
bs = tmp;
}
return bs;
}