@Test void testSharedSecretBytes() { KeyPair kp = SECP256K1.KeyPair.random(); KeyPair otherKP = SECP256K1.KeyPair.random(); Bytes32 sharedSecret = SECP256K1.calculateKeyAgreement(kp.secretKey(), otherKP.publicKey()); Bytes32 otherSharedSecret = SECP256K1.calculateKeyAgreement(otherKP.secretKey(), kp.publicKey()); assertEquals(sharedSecret, otherSharedSecret); }
public static Bytes32 calculateKeyAgreement(SecretKey privKey, PublicKey theirPubKey) { checkArgument(privKey != null, "missing private key"); checkArgument(theirPubKey != null, "missing remote public key"); ECPrivateKeyParameters privKeyP = new ECPrivateKeyParameters(privKey.bytes().toUnsignedBigInteger(), Parameters.CURVE); ECPublicKeyParameters pubKeyP = new ECPublicKeyParameters(theirPubKey.asEcPoint(), Parameters.CURVE); ECDHBasicAgreement agreement = new ECDHBasicAgreement(); agreement.init(privKeyP); return UInt256.valueOf(agreement.calculateAgreement(pubKeyP)).toBytes(); }
SECP256K1 { public static Bytes32 calculateKeyAgreement(SecretKey privKey, PublicKey theirPubKey) { checkArgument(privKey != null, "missing private key"); checkArgument(theirPubKey != null, "missing remote public key"); ECPrivateKeyParameters privKeyP = new ECPrivateKeyParameters(privKey.bytes().toUnsignedBigInteger(), Parameters.CURVE); ECPublicKeyParameters pubKeyP = new ECPublicKeyParameters(theirPubKey.asEcPoint(), Parameters.CURVE); ECDHBasicAgreement agreement = new ECDHBasicAgreement(); agreement.init(privKeyP); return UInt256.valueOf(agreement.calculateAgreement(pubKeyP)).toBytes(); } }
SECP256K1 { public static Bytes32 calculateKeyAgreement(SecretKey privKey, PublicKey theirPubKey) { checkArgument(privKey != null, "missing private key"); checkArgument(theirPubKey != null, "missing remote public key"); ECPrivateKeyParameters privKeyP = new ECPrivateKeyParameters(privKey.bytes().toUnsignedBigInteger(), Parameters.CURVE); ECPublicKeyParameters pubKeyP = new ECPublicKeyParameters(theirPubKey.asEcPoint(), Parameters.CURVE); ECDHBasicAgreement agreement = new ECDHBasicAgreement(); agreement.init(privKeyP); return UInt256.valueOf(agreement.calculateAgreement(pubKeyP)).toBytes(); } private  SECP256K1(); }
SECP256K1 { public static Bytes32 calculateKeyAgreement(SecretKey privKey, PublicKey theirPubKey) { checkArgument(privKey != null, "missing private key"); checkArgument(theirPubKey != null, "missing remote public key"); ECPrivateKeyParameters privKeyP = new ECPrivateKeyParameters(privKey.bytes().toUnsignedBigInteger(), Parameters.CURVE); ECPublicKeyParameters pubKeyP = new ECPublicKeyParameters(theirPubKey.asEcPoint(), Parameters.CURVE); ECDHBasicAgreement agreement = new ECDHBasicAgreement(); agreement.init(privKeyP); return UInt256.valueOf(agreement.calculateAgreement(pubKeyP)).toBytes(); } private  SECP256K1(); static Signature sign(byte[] data, KeyPair keyPair); static Signature sign(Bytes data, KeyPair keyPair); static Signature signHashed(byte[] hash, KeyPair keyPair); static Signature signHashed(Bytes32 hash, KeyPair keyPair); static boolean verify(byte[] data, Signature signature, PublicKey publicKey); static boolean verify(Bytes data, Signature signature, PublicKey publicKey); static boolean verifyHashed(Bytes32 hash, Signature signature, PublicKey publicKey); static boolean verifyHashed(byte[] hash, Signature signature, PublicKey publicKey); static Bytes32 calculateKeyAgreement(SecretKey privKey, PublicKey theirPubKey); }
SECP256K1 { public static Bytes32 calculateKeyAgreement(SecretKey privKey, PublicKey theirPubKey) { checkArgument(privKey != null, "missing private key"); checkArgument(theirPubKey != null, "missing remote public key"); ECPrivateKeyParameters privKeyP = new ECPrivateKeyParameters(privKey.bytes().toUnsignedBigInteger(), Parameters.CURVE); ECPublicKeyParameters pubKeyP = new ECPublicKeyParameters(theirPubKey.asEcPoint(), Parameters.CURVE); ECDHBasicAgreement agreement = new ECDHBasicAgreement(); agreement.init(privKeyP); return UInt256.valueOf(agreement.calculateAgreement(pubKeyP)).toBytes(); } private  SECP256K1(); static Signature sign(byte[] data, KeyPair keyPair); static Signature sign(Bytes data, KeyPair keyPair); static Signature signHashed(byte[] hash, KeyPair keyPair); static Signature signHashed(Bytes32 hash, KeyPair keyPair); static boolean verify(byte[] data, Signature signature, PublicKey publicKey); static boolean verify(Bytes data, Signature signature, PublicKey publicKey); static boolean verifyHashed(Bytes32 hash, Signature signature, PublicKey publicKey); static boolean verifyHashed(byte[] hash, Signature signature, PublicKey publicKey); static Bytes32 calculateKeyAgreement(SecretKey privKey, PublicKey theirPubKey);  }