本文整理汇总了Java中org.bitcoinj.core.ECKey.sign方法的典型用法代码示例。如果您正苦于以下问题:Java ECKey.sign方法的具体用法?Java ECKey.sign怎么用?Java ECKey.sign使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bitcoinj.core.ECKey
的用法示例。
在下文中一共展示了ECKey.sign方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSignatureBytes
import org.bitcoinj.core.ECKey; //导入方法依赖的package包/类
/**
* Get array bayts signature
*
* @param chainId
* id chain (golos or steem)
* @param requiredPrivateKey
* this is private key
* @return signature bytes
*/
protected byte[] getSignatureBytes(String chainId, ECKey requiredPrivateKey) {
boolean isGrapheneCanonical = false;
byte[] signatureData = null;
while (!isGrapheneCanonical) {
List<Byte> serializedTransaction = this.toBytes();
List<Byte> listBytes = new ArrayList<Byte>();
listBytes.addAll(Util.hexToBytes(chainId));
listBytes.addAll(serializedTransaction);
byte[] arrayBytes = Util.listBytes2array(listBytes);
Sha256Hash hashTransaction = Sha256Hash
.wrap(Sha256Hash.hash(arrayBytes));
int recId = -1;
ECKey.ECDSASignature sig = requiredPrivateKey.sign(hashTransaction);
for (int i = 0; i < 4; i++) {
ECKey k = ECKey.recoverFromSignature(i, sig, hashTransaction,
requiredPrivateKey.isCompressed());
if (k != null && k.getPubKeyPoint()
.equals(requiredPrivateKey.getPubKeyPoint())) {
recId = i;
break;
}
}
// 1 header + 32 bytes for R + 32 bytes for S
signatureData = new byte[65];
int headerByte = recId + 27 + (requiredPrivateKey.isCompressed() ? 4 : 0);
signatureData[0] = (byte) headerByte;
System.arraycopy(Utils.bigIntegerToBytes(sig.r, 32), 0,
signatureData, 1, 32);
System.arraycopy(Utils.bigIntegerToBytes(sig.s, 32), 0,
signatureData, 33, 32);
// Further "canonicality" tests
if (isCanonical(signatureData)) {
this.setExpiration(Util.addTime(this.getExpiration(), 1));
} else {
isGrapheneCanonical = true;
}
}
return signatureData;
}
示例2: sign
import org.bitcoinj.core.ECKey; //导入方法依赖的package包/类
private ECDSASignature sign(Sha256Hash hash, ECKey signingKey) {
return signingKey.sign(hash);
}