本文整理了Java中org.spongycastle.math.ec.ECCurve.decodePoint()
方法的一些代码示例,展示了ECCurve.decodePoint()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ECCurve.decodePoint()
方法的具体详情如下:
包路径:org.spongycastle.math.ec.ECCurve
类名称:ECCurve
方法名:decodePoint
[英]Decode a point on this curve from its ASN.1 encoding. The different encodings are taken account of, including point compression for Fp
(X9.62 s 4.2.1 pg 17).
[中]
代码示例来源:origin: ethereum/ethereumj
static AuthResponseMessage decode(byte[] wire) {
int offset = 0;
AuthResponseMessage message = new AuthResponseMessage();
byte[] bytes = new byte[65];
System.arraycopy(wire, offset, bytes, 1, 64);
offset += 64;
bytes[0] = 0x04; // uncompressed
message.ephemeralPublicKey = ECKey.CURVE.getCurve().decodePoint(bytes);
message.nonce = new byte[32];
System.arraycopy(wire, offset, message.nonce, 0, 32);
offset += message.nonce.length;
byte tokenUsed = wire[offset];
offset += 1;
if (tokenUsed != 0x00 && tokenUsed != 0x01)
throw new RuntimeException("invalid boolean"); // TODO specific exception
message.isTokenUsed = (tokenUsed == 0x01);
return message;
}
代码示例来源:origin: ethereum/ethereumj
/**
* Utility for compressing an elliptic curve point. Returns the same point if it's already compressed.
* See the ECKey class docs for a discussion of point compression.
*
* @param uncompressed -
*
* @return -
* @deprecated per-point compression property will be removed in Bouncy Castle
*/
public static ECPoint compressPoint(ECPoint uncompressed) {
return CURVE.getCurve().decodePoint(uncompressed.getEncoded(true));
}
代码示例来源:origin: ethereum/ethereumj
/**
* Utility for decompressing an elliptic curve point. Returns the same point if it's already compressed.
* See the ECKey class docs for a discussion of point compression.
*
* @param compressed -
*
* @return -
* @deprecated per-point compression property will be removed in Bouncy Castle
*/
public static ECPoint decompressPoint(ECPoint compressed) {
return CURVE.getCurve().decodePoint(compressed.getEncoded(false));
}
代码示例来源:origin: ethereum/ethereumj
/**
* Creates an ECKey that cannot be used for signing, only verifying signatures, from the given encoded point.
* The compression state of pub will be preserved.
*
* @param pub -
* @return -
*/
public static ECKey fromPublicOnly(byte[] pub) {
return new ECKey(null, CURVE.getCurve().decodePoint(pub));
}
代码示例来源:origin: ethereum/ethereumj
public static byte[] decrypt(BigInteger privKey, byte[] cipher, byte[] macData) throws IOException, InvalidCipherTextException {
byte[] plaintext;
ByteArrayInputStream is = new ByteArrayInputStream(cipher);
byte[] ephemBytes = new byte[2*((CURVE.getCurve().getFieldSize()+7)/8) + 1];
is.read(ephemBytes);
ECPoint ephem = CURVE.getCurve().decodePoint(ephemBytes);
byte[] IV = new byte[KEY_SIZE /8];
is.read(IV);
byte[] cipherBody = new byte[is.available()];
is.read(cipherBody);
plaintext = decrypt(ephem, privKey, IV, cipherBody, macData);
return plaintext;
}
代码示例来源:origin: ethereum/ethereumj
static AuthInitiateMessage decode(byte[] wire) {
AuthInitiateMessage message = new AuthInitiateMessage();
int offset = 0;
byte[] r = new byte[32];
byte[] s = new byte[32];
System.arraycopy(wire, offset, r, 0, 32);
offset += 32;
System.arraycopy(wire, offset, s, 0, 32);
offset += 32;
int v = wire[offset] + 27;
offset += 1;
message.signature = ECKey.ECDSASignature.fromComponents(r, s, (byte)v);
message.ephemeralPublicHash = new byte[32];
System.arraycopy(wire, offset, message.ephemeralPublicHash, 0, 32);
offset += 32;
byte[] bytes = new byte[65];
System.arraycopy(wire, offset, bytes, 1, 64);
offset += 64;
bytes[0] = 0x04; // uncompressed
message.publicKey = ECKey.CURVE.getCurve().decodePoint(bytes);
message.nonce = new byte[32];
System.arraycopy(wire, offset, message.nonce, 0, 32);
offset += message.nonce.length;
byte tokenUsed = wire[offset];
offset += 1;
if (tokenUsed != 0x00 && tokenUsed != 0x01)
throw new RuntimeException("invalid boolean"); // TODO specific exception
message.isTokenUsed = (tokenUsed == 0x01);
return message;
}
代码示例来源:origin: ethereum/ethereumj
/**
* Creates an ECKey that simply trusts the caller to ensure that point is really the result of multiplying the
* generator point by the private key. This is used to speed things up when you know you have the right values
* already. The compression state of the point will be preserved.
*
* @param priv -
* @param pub -
* @return -
*/
public static ECKey fromPrivateAndPrecalculatedPublic(byte[] priv, byte[] pub) {
check(priv != null, "Private key must not be null");
check(pub != null, "Public key must not be null");
return new ECKey(new BigInteger(1, priv), CURVE.getCurve().decodePoint(pub));
}
代码示例来源:origin: ethereum/ethereumj
/**
* Decompress a compressed public key (x co-ord and low-bit of y-coord).
*
* @param xBN -
* @param yBit -
* @return -
*/
private static ECPoint decompressKey(BigInteger xBN, boolean yBit) {
X9IntegerConverter x9 = new X9IntegerConverter();
byte[] compEnc = x9.integerToBytes(xBN, 1 + x9.getByteLength(CURVE.getCurve()));
compEnc[0] = (byte) (yBit ? 0x03 : 0x02);
return CURVE.getCurve().decodePoint(compEnc);
}
代码示例来源:origin: ethereum/ethereumj
/**
* <p>Verifies the given ECDSA signature against the message bytes using the public key bytes.</p>
*
* <p>When using native ECDSA verification, data must be 32 bytes, and no element may be
* larger than 520 bytes.</p>
*
* @param data Hash of the data to verify.
* @param signature signature.
* @param pub The public key bytes to use.
*
* @return -
*/
public static boolean verify(byte[] data, ECDSASignature signature, byte[] pub) {
ECDSASigner signer = new ECDSASigner();
ECPublicKeyParameters params = new ECPublicKeyParameters(CURVE.getCurve().decodePoint(pub), CURVE);
signer.init(false, params);
try {
return signer.verifySignature(data, signature.r, signature.s);
} catch (NullPointerException npe) {
// Bouncy Castle contains a bug that can cause NPEs given specially crafted signatures.
// Those signatures are inherently invalid/attack sigs so we just fail them here rather than crash the thread.
logger.error("Caught NPE inside bouncy castle", npe);
return false;
}
}
代码示例来源:origin: ethereum/ethereumj
public static byte[] decrypt(BigInteger prv, byte[] cipher) throws InvalidCipherTextException, IOException {
ByteArrayInputStream is = new ByteArrayInputStream(cipher);
byte[] ephemBytes = new byte[2*((curve.getCurve().getFieldSize()+7)/8) + 1];
is.read(ephemBytes);
ECPoint ephem = curve.getCurve().decodePoint(ephemBytes);
byte[] IV = new byte[KEY_SIZE /8];
is.read(IV);
byte[] cipherBody = new byte[is.available()];
is.read(cipherBody);
EthereumIESEngine iesEngine = makeIESEngine(false, ephem, prv, IV);
byte[] message = iesEngine.processBlock(cipherBody, 0, cipherBody.length);
return message;
}
代码示例来源:origin: ethereum/ethereumj
static AuthResponseMessageV4 decode(byte[] wire) {
AuthResponseMessageV4 message = new AuthResponseMessageV4();
RLPList params = (RLPList) RLP.decode2OneItem(wire, 0);
byte[] pubKeyBytes = params.get(0).getRLPData();
byte[] bytes = new byte[65];
System.arraycopy(pubKeyBytes, 0, bytes, 1, 64);
bytes[0] = 0x04; // uncompressed
message.ephemeralPublicKey = ECKey.CURVE.getCurve().decodePoint(bytes);
message.nonce = params.get(1).getRLPData();
byte[] versionBytes = params.get(2).getRLPData();
message.version = ByteUtil.byteArrayToInt(versionBytes);
return message;
}
代码示例来源:origin: ethereum/ethereumj
static AuthInitiateMessageV4 decode(byte[] wire) {
AuthInitiateMessageV4 message = new AuthInitiateMessageV4();
RLPList params = (RLPList) RLP.decode2OneItem(wire, 0);
byte[] signatureBytes = params.get(0).getRLPData();
int offset = 0;
byte[] r = new byte[32];
byte[] s = new byte[32];
System.arraycopy(signatureBytes, offset, r, 0, 32);
offset += 32;
System.arraycopy(signatureBytes, offset, s, 0, 32);
offset += 32;
int v = signatureBytes[offset] + 27;
message.signature = ECKey.ECDSASignature.fromComponents(r, s, (byte)v);
byte[] publicKeyBytes = params.get(1).getRLPData();
byte[] bytes = new byte[65];
System.arraycopy(publicKeyBytes, 0, bytes, 1, 64);
bytes[0] = 0x04; // uncompressed
message.publicKey = ECKey.CURVE.getCurve().decodePoint(bytes);
message.nonce = params.get(2).getRLPData();
byte[] versionBytes = params.get(3).getRLPData();
message.version = ByteUtil.byteArrayToInt(versionBytes);
return message;
}
代码示例来源:origin: cash.bitcoinj/bitcoinj-core
public ECPoint get() {
if (point == null)
point = curve.decodePoint(bits);
return point;
}
代码示例来源:origin: com.madgag.spongycastle/bcpg-jdk15on
static ECPoint decodePoint(
BigInteger encodedPoint,
ECCurve curve)
throws IOException
{
return curve.decodePoint(BigIntegers.asUnsignedByteArray(encodedPoint));
}
}
代码示例来源:origin: com.madgag.spongycastle/bcpg-jdk15on
static ECPoint decodePoint(
BigInteger encodedPoint,
ECCurve curve)
throws IOException
{
return curve.decodePoint(BigIntegers.asUnsignedByteArray(encodedPoint));
}
代码示例来源:origin: cash.bitcoinj/bitcoinj-core
/**
* Creates an ECKey that simply trusts the caller to ensure that point is really the result of multiplying the
* generator point by the private key. This is used to speed things up when you know you have the right values
* already. The compression state of the point will be preserved.
*/
public static ECKey fromPrivateAndPrecalculatedPublic(byte[] priv, byte[] pub) {
checkNotNull(priv);
checkNotNull(pub);
return new ECKey(new BigInteger(1, priv), CURVE.getCurve().decodePoint(pub));
}
代码示例来源:origin: cash.bitcoinj/bitcoinj-core
/**
* Creates an ECKey that cannot be used for signing, only verifying signatures, from the given encoded point.
* The compression state of pub will be preserved.
*/
public static ECKey fromPublicOnly(byte[] pub) {
return new ECKey(null, CURVE.getCurve().decodePoint(pub));
}
代码示例来源:origin: com.madgag.spongycastle/core
public synchronized ECPoint getPoint()
{
if (p == null)
{
p = c.decodePoint(encoding.getOctets()).normalize();
}
return p;
}
代码示例来源:origin: nuls-io/nuls
public static boolean verify(byte[] data, ECDSASignature signature, byte[] pub) {
ECDSASigner signer = new ECDSASigner();
ECPublicKeyParameters params = new ECPublicKeyParameters(CURVE.getCurve().decodePoint(pub), CURVE);
signer.init(false, params);
try {
return signer.verifySignature(data, signature.r, signature.s);
} catch (NullPointerException e) {
log.error("Caught NPE inside bouncy castle", e);
return false;
}
}
代码示例来源:origin: cash.bitcoinj/bitcoinj-core
/** Decompress a compressed public key (x co-ord and low-bit of y-coord). */
private static ECPoint decompressKey(BigInteger xBN, boolean yBit) {
X9IntegerConverter x9 = new X9IntegerConverter();
byte[] compEnc = x9.integerToBytes(xBN, 1 + x9.getByteLength(CURVE.getCurve()));
compEnc[0] = (byte)(yBit ? 0x03 : 0x02);
return CURVE.getCurve().decodePoint(compEnc);
}
内容来源于网络,如有侵权,请联系作者删除!