本文整理匯總了Java中org.spongycastle.math.ec.ECPoint類的典型用法代碼示例。如果您正苦於以下問題:Java ECPoint類的具體用法?Java ECPoint怎麽用?Java ECPoint使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ECPoint類屬於org.spongycastle.math.ec包,在下文中一共展示了ECPoint類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: decrypt
import org.spongycastle.math.ec.ECPoint; //導入依賴的package包/類
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;
}
示例2: byteArrayToECPoint
import org.spongycastle.math.ec.ECPoint; //導入依賴的package包/類
private static ECPoint byteArrayToECPoint(final byte[] value, final ECCurve.Fp curve)
throws IllegalArgumentException {
final byte[] x = new byte[(value.length - 1) / 2];
final byte[] y = new byte[(value.length - 1) / 2];
if (value[0] != (byte) 0x04) {
throw new IllegalArgumentException("No uncompressed Point found!"); //$NON-NLS-1$
}
System.arraycopy(value, 1, x, 0, (value.length - 1) / 2);
System.arraycopy(value, 1 + (value.length - 1) / 2, y, 0,
(value.length - 1) / 2);
final ECFieldElement.Fp xE = (org.spongycastle.math.ec.ECFieldElement.Fp) curve.fromBigInteger(new BigInteger(1, x));
final ECFieldElement.Fp yE = (org.spongycastle.math.ec.ECFieldElement.Fp) curve.fromBigInteger(new BigInteger(1, y));
final ECPoint point = curve.createPoint(xE.toBigInteger(), yE.toBigInteger());
return point;
}
示例3: makeIESEngine
import org.spongycastle.math.ec.ECPoint; //導入依賴的package包/類
private static EthereumIESEngine makeIESEngine(boolean isEncrypt, ECPoint pub, BigInteger prv, byte[] IV) {
AESFastEngine aesFastEngine = new AESFastEngine();
EthereumIESEngine iesEngine = new EthereumIESEngine(
new ECDHBasicAgreement(),
new ConcatKDFBytesGenerator(new SHA256Digest()),
new HMac(new SHA256Digest()),
new SHA256Digest(),
new BufferedBlockCipher(new SICBlockCipher(aesFastEngine)));
byte[] d = new byte[] {};
byte[] e = new byte[] {};
IESParameters p = new IESWithCipherParameters(d, e, KEY_SIZE, KEY_SIZE);
ParametersWithIV parametersWithIV = new ParametersWithIV(p, IV);
iesEngine.init(isEncrypt, new ECPrivateKeyParameters(prv, curve), new ECPublicKeyParameters(pub, curve), parametersWithIV);
return iesEngine;
}
示例4: decrypt
import org.spongycastle.math.ec.ECPoint; //導入依賴的package包/類
public static byte[] decrypt(ECPoint ephem, BigInteger prv, byte[] iv, byte[] cipher, byte[] macData) throws InvalidCipherTextException {
AESFastEngine aesFastEngine = new AESFastEngine();
EthereumIESEngine iesEngine = new EthereumIESEngine(
new ECDHBasicAgreement(),
new ConcatKDFBytesGenerator(new SHA256Digest()),
new HMac(new SHA256Digest()),
new SHA256Digest(),
new BufferedBlockCipher(new SICBlockCipher(aesFastEngine)));
byte[] d = new byte[] {};
byte[] e = new byte[] {};
IESParameters p = new IESWithCipherParameters(d, e, KEY_SIZE, KEY_SIZE);
ParametersWithIV parametersWithIV =
new ParametersWithIV(p, iv);
iesEngine.init(false, new ECPrivateKeyParameters(prv, CURVE), new ECPublicKeyParameters(ephem, CURVE), parametersWithIV);
return iesEngine.processBlock(cipher, 0, cipher.length, macData);
}
示例5: makeIESEngine
import org.spongycastle.math.ec.ECPoint; //導入依賴的package包/類
private static EthereumIESEngine makeIESEngine(boolean isEncrypt, ECPoint pub, BigInteger prv, byte[] iv) {
AESFastEngine aesFastEngine = new AESFastEngine();
EthereumIESEngine iesEngine = new EthereumIESEngine(
new ECDHBasicAgreement(),
new ConcatKDFBytesGenerator(new SHA256Digest()),
new HMac(new SHA256Digest()),
new SHA256Digest(),
new BufferedBlockCipher(new SICBlockCipher(aesFastEngine)));
byte[] d = new byte[] {};
byte[] e = new byte[] {};
IESParameters p = new IESWithCipherParameters(d, e, KEY_SIZE, KEY_SIZE);
ParametersWithIV parametersWithIV = new ParametersWithIV(p, iv);
iesEngine.init(isEncrypt, new ECPrivateKeyParameters(prv, CURVE), new ECPublicKeyParameters(pub, CURVE), parametersWithIV);
return iesEngine;
}
示例6: ECKey
import org.spongycastle.math.ec.ECPoint; //導入依賴的package包/類
/**
* Pair a private key with a public EC point.
*
* All private key operations will use the provider.
*/
public ECKey(Provider provider, @Nullable PrivateKey privKey, ECPoint pub) {
this.provider = provider;
if (privKey == null || isECPrivateKey(privKey)) {
this.privKey = privKey;
} else {
throw new IllegalArgumentException(
"Expected EC private key, given a private key object with class " +
privKey.getClass().toString() +
" and algorithm " + privKey.getAlgorithm());
}
if (pub == null) {
throw new IllegalArgumentException("Public key may not be null");
} else {
this.pub = pub;
}
}
示例7: ECKey
import org.spongycastle.math.ec.ECPoint; //導入依賴的package包/類
/**
* Creates an ECKey given either the private key only, the public key only, or both. If only the private key
* is supplied, the public key will be calculated from it (this is slow). If both are supplied, it's assumed
* the public key already correctly matches the private key. If only the public key is supplied, this ECKey cannot
* be used for signing.
* @param compressed If set to true and pubKey is null, the derived public key will be in compressed form.
*/
@Deprecated
public ECKey(@Nullable BigInteger privKey, @Nullable byte[] pubKey, boolean compressed) {
if (privKey == null && pubKey == null)
throw new IllegalArgumentException("ECKey requires at least private or public key");
this.priv = privKey;
if (pubKey == null) {
// Derive public from private.
ECPoint point = publicPointFromPrivate(privKey);
point = getPointWithCompression(point, compressed);
this.pub = new LazyECPoint(point);
} else {
// We expect the pubkey to be in regular encoded form, just as a BigInteger. Therefore the first byte is
// a special marker byte.
// TODO: This is probably not a useful API and may be confusing.
this.pub = new LazyECPoint(CURVE.getCurve(), pubKey);
}
}
示例8: extractPublicKey
import org.spongycastle.math.ec.ECPoint; //導入依賴的package包/類
private static ECPoint extractPublicKey(final ECPublicKey ecPublicKey) {
final java.security.spec.ECPoint publicPointW = ecPublicKey.getW();
final BigInteger xCoord = publicPointW.getAffineX();
final BigInteger yCoord = publicPointW.getAffineY();
return CURVE.getCurve().createPoint(xCoord, yCoord);
}
示例9: ECKey
import org.spongycastle.math.ec.ECPoint; //導入依賴的package包/類
/**
* Pair a private key integer with a public EC point
*
* BouncyCastle will be used as the Java Security Provider
*/
public ECKey(@Nullable BigInteger priv, ECPoint pub) {
this(
SpongyCastleProvider.getInstance(),
privateKeyFromBigInteger(priv),
pub
);
}
示例10: extractPublicKey
import org.spongycastle.math.ec.ECPoint; //導入依賴的package包/類
private static ECPoint extractPublicKey(ECPublicKey ecPublicKey) {
java.security.spec.ECPoint publicPointW = ecPublicKey.getW();
BigInteger xCoord = publicPointW.getAffineX();
BigInteger yCoord = publicPointW.getAffineY();
return CURVE.getCurve()
.createPoint(xCoord, yCoord);
}
示例11: testRoundTrip
import org.spongycastle.math.ec.ECPoint; //導入依賴的package包/類
@Test
public void testRoundTrip() throws InvalidCipherTextException, IOException {
ECPoint pub1 = pub(PRIVATE_KEY1);
byte[] plaintext = "Hello world".getBytes();
byte[] ciphertext = encrypt(pub1, plaintext);
byte[] plaintext1 = decrypt(PRIVATE_KEY1, ciphertext);
assertArrayEquals(plaintext, plaintext1);
}
示例12: EncryptionHandshake
import org.spongycastle.math.ec.ECPoint; //導入依賴的package包/類
public EncryptionHandshake(ECPoint remotePublicKey) {
this.remotePublicKey = remotePublicKey;
ephemeralKey = new ECKey(random);
initiatorNonce = new byte[NONCE_SIZE];
random.nextBytes(initiatorNonce);
isInitiator = true;
}
示例13: DeterministicKey
import org.spongycastle.math.ec.ECPoint; //導入依賴的package包/類
public DeterministicKey(ImmutableList<ChildNumber> childNumberPath,
byte[] chainCode,
ECPoint publicAsPoint,
@Nullable BigInteger priv,
@Nullable DeterministicKey parent) {
this(childNumberPath, chainCode, new LazyECPoint(publicAsPoint), priv, parent);
}
示例14: encrypt
import org.spongycastle.math.ec.ECPoint; //導入依賴的package包/類
public static byte[] encrypt(ECPoint toPub, byte[] plaintext) throws InvalidCipherTextException, IOException {
ECKeyPairGenerator eGen = new ECKeyPairGenerator();
SecureRandom random = new SecureRandom();
KeyGenerationParameters gParam = new ECKeyGenerationParameters(curve, random);
eGen.init(gParam);
byte[] IV = new byte[KEY_SIZE/8];
new SecureRandom().nextBytes(IV);
AsymmetricCipherKeyPair ephemPair = eGen.generateKeyPair();
BigInteger prv = ((ECPrivateKeyParameters)ephemPair.getPrivate()).getD();
ECPoint pub = ((ECPublicKeyParameters)ephemPair.getPublic()).getQ();
EthereumIESEngine iesEngine = makeIESEngine(true, toPub, prv, IV);
ECKeyGenerationParameters keygenParams = new ECKeyGenerationParameters(curve, random);
ECKeyPairGenerator generator = new ECKeyPairGenerator();
generator.init(keygenParams);
ECKeyPairGenerator gen = new ECKeyPairGenerator();
gen.init(new ECKeyGenerationParameters(ECKey.CURVE, random));
byte[] cipher = iesEngine.processBlock(plaintext, 0, plaintext.length);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bos.write(pub.getEncoded(false));
bos.write(IV);
bos.write(cipher);
return bos.toByteArray();
}
示例15: ECKey
import org.spongycastle.math.ec.ECPoint; //導入依賴的package包/類
/**
* Pair a private key integer with a public EC point
*
* BouncyCastle will be used as the Java Security Provider
*/
public ECKey(@Nullable BigInteger priv, ECPoint pub) {
this(
SpongyCastleProvider.getInstance(),
privateKeyFromBigInteger(priv),
pub
);
}