本文整理汇总了Java中com.google.bitcoin.core.ECKey.ECDSASignature类的典型用法代码示例。如果您正苦于以下问题:Java ECDSASignature类的具体用法?Java ECDSASignature怎么用?Java ECDSASignature使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ECDSASignature类属于com.google.bitcoin.core.ECKey包,在下文中一共展示了ECDSASignature类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testEcKeySign
import com.google.bitcoin.core.ECKey.ECDSASignature; //导入依赖的package包/类
@Test
public void testEcKeySign() {
String password = "pass1234";
String challenge = "challenge1234";
byte[] secretTarget = Utils.doubleDigest(password.getBytes());
ECKey key = new ECKey(new BigInteger(1, secretTarget), null, true);
ECDSASignature sign = key.sign(Sha256Hash.createDouble(challenge
.getBytes()));
assertNotNull(sign);
System.out.println("sign.r=" + sign.r);
System.out.println("sign.s=" + sign.s);
String signHex = BaseEncoding.base16().encode(sign.encodeToDER());
System.out.println(signHex);
byte[] sign2byte = BaseEncoding.base16().decode(signHex);
ECDSASignature signTarget = ECDSASignature.decodeFromDER(sign2byte);
assertFalse(ECKey.verify(
Sha256Hash.createDouble("FakeChallenge".getBytes()).getBytes(),
signTarget, key.getPubKey()));
assertTrue(ECKey.verify(Sha256Hash.createDouble(challenge.getBytes())
.getBytes(), signTarget, key.getPubKey()));
}
示例2: sign
import com.google.bitcoin.core.ECKey.ECDSASignature; //导入依赖的package包/类
protected TransactionSignature sign(int vin, ECKey key) {
Sha256Hash sighash = tx.hashForSignature(vin, tx.getInput(vin).getConnectedOutput().getScriptBytes(),
Transaction.SigHash.ALL, false);
ECDSASignature sig = key.sign(sighash);
return new TransactionSignature(sig, Transaction.SigHash.ALL, false);
}