本文整理汇总了Java中org.bouncycastle.util.BigIntegers.fromUnsignedByteArray方法的典型用法代码示例。如果您正苦于以下问题:Java BigIntegers.fromUnsignedByteArray方法的具体用法?Java BigIntegers.fromUnsignedByteArray怎么用?Java BigIntegers.fromUnsignedByteArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.util.BigIntegers
的用法示例。
在下文中一共展示了BigIntegers.fromUnsignedByteArray方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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);
}
示例3: importKey
import org.bouncycastle.util.BigIntegers; //导入方法依赖的package包/类
@Override
public Optional<ECPrivateKey> importKey(String curveName, byte[] data) {
X9ECParameters x9ECParameters = ECAssistant.x9ECParameters(curveName);
int fieldLength = ECAssistant.fieldLength(x9ECParameters);
if (fieldLength(data.length) != fieldLength) {
logger.warn("-- importKey() - bad data length: {} curve: {} data:0x{}",
data.length, curveName, Hex.toHexString(data));
}
BigInteger x = BigIntegers.fromUnsignedByteArray(data, 0, fieldLength);
BigInteger y = ECPointsCompact.y(x9ECParameters.getCurve(), x);
BigInteger d = BigIntegers.fromUnsignedByteArray(data, fieldLength, fieldLength);
return ECKeyFactories.privateKeyFactory()
.createECPrivateKey(x, y, d, curveName);
}
示例4: importKey
import org.bouncycastle.util.BigIntegers; //导入方法依赖的package包/类
@Override
public Optional<ECPublicKey> importKey(String curveName, byte[] data) {
X9ECParameters x9ECParameters = ECAssistant.x9ECParameters(curveName);
int fieldLength = ECAssistant.fieldLength(x9ECParameters);
if (fieldLength(data.length) != fieldLength) {
logger.warn("-- importKey() - bad data length: {} curve: {} data:0x{}",
data.length, curveName, Hex.toHexString(data));
}
BigInteger x = BigIntegers.fromUnsignedByteArray(data);
BigInteger y = ECPointsCompact.y(x9ECParameters.getCurve(), x);
return ECKeyFactories.publicKeyFactory()
.createECPublicKey(x, y, curveName);
}
示例5: importKey
import org.bouncycastle.util.BigIntegers; //导入方法依赖的package包/类
@Override
public Optional<ECPrivateKey> 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));
}
BigInteger d = BigIntegers.fromUnsignedByteArray(data, 0, fieldLength);
return ECKeyFactories.privateKeyFactory()
.createECPrivateKey(d, curveName);
}
示例6: injectiveEncode
import org.bouncycastle.util.BigIntegers; //导入方法依赖的package包/类
/**
* We encode the message using a probabilistic algorithm.
*
* @param msg The message to be encoded
* @param rand
* @return
* @throws UnsupportedOperationException
*/
@Override
public ECPoint injectiveEncode(byte[] msg, Random rand) throws UnsupportedOperationException {
final int BLOCK_LEN = getInjectiveEncodeMsgLength();
ECCurve curve = curveParams.getCurve();
if (!(curve instanceof ECCurve.AbstractFp)) {
throw new UnsupportedOperationException("We currently only support prime fields for message encoding");
}
ECCurve.AbstractFp curveFp = (ECCurve.AbstractFp) curve;
if (msg.length != BLOCK_LEN) {
if (msg.length > BLOCK_LEN)
logger.warn("Message larger than maximum length ({} bytes, field size is {} bytes), truncating", msg.length,
BLOCK_LEN);
byte[] tmp = new byte[BLOCK_LEN];
System.arraycopy(msg, 0, tmp, 0, Math.min(tmp.length, msg.length));
msg = tmp;
}
// For now we use a probabilistic method.
ECFieldElement A = curveFp.getA();
ECFieldElement B = curveFp.getB();
BigInteger M = BigIntegers.fromUnsignedByteArray(msg);
ECFieldElement y = null;
ECFieldElement x = null;
byte[] randBytes = new byte[NONCE_LENGTH];
for (int j = 0; j < (1 << LOG_LOG_ENCODING_ERROR_RATE); ++j) {
rand.nextBytes(randBytes);
x = curveFp.fromBigInteger(
BigIntegers.fromUnsignedByteArray(randBytes)
.shiftLeft(BLOCK_LEN * 8).or(M));
ECFieldElement z = x.square().multiplyPlusProduct(x,A,x).add(B);
y = z.sqrt();
if (y != null)
break;
}
if (y == null) {
logger.error("Miracle! Didn't find mapping for msg -- occurs with prob 2^{-{}}", 1<< LOG_LOG_ENCODING_ERROR_RATE);
return null;
}
return curveFp.createPoint(x.toBigInteger(), y.toBigInteger());
}