use of com.jd.blockchain.crypto.SignatureDigest in project jdchain-core by blockchain-jd-com.
the class LedgerInitializeWebController method signPermissionRequest.
public SignatureDigest signPermissionRequest(int requesterId, PrivKey privKey) {
byte[] reqAuthBytes = BytesUtils.concat(BytesUtils.toBytes(requesterId), ledgerInitConfig.getLedgerSettings().getLedgerSeed());
SignatureFunction signatureFunction = Crypto.getSignatureFunction(privKey.getAlgorithm());
SignatureDigest reqAuthSign = signatureFunction.sign(privKey, reqAuthBytes);
return reqAuthSign;
}
use of com.jd.blockchain.crypto.SignatureDigest in project jdchain-core by blockchain-jd-com.
the class LedgerTransactionDataTest method initTxRequestMessage.
private TxRequestMessage initTxRequestMessage(CryptoAlgorithm hashAlgorithm) throws Exception {
TransactionContent txContent = initTransactionContent();
HashDigest txHash = TxBuilder.computeTxContentHash(hashAlgorithm, txContent);
TxRequestMessage txRequestMessage = new TxRequestMessage(txHash, txContent);
AsymmetricKeypair keypair2 = ClassicCryptoService.ED25519.generateKeypair();
SignatureDigest digest1 = ClassicCryptoService.ED25519.sign(keypair.getPrivKey(), "zhangsan".getBytes());
SignatureDigest digest2 = ClassicCryptoService.ED25519.sign(keypair.getPrivKey(), "lisi".getBytes());
DigitalSignatureBlob endPoint1 = new DigitalSignatureBlob(keypair.getPubKey(), digest1);
DigitalSignatureBlob endPoint2 = new DigitalSignatureBlob(keypair2.getPubKey(), digest2);
txRequestMessage.addEndpointSignatures(endPoint1);
txRequestMessage.addEndpointSignatures(endPoint2);
AsymmetricKeypair keypair4 = ClassicCryptoService.ED25519.generateKeypair();
SignatureDigest digest3 = ClassicCryptoService.ED25519.sign(keypair.getPrivKey(), "wangwu".getBytes());
SignatureDigest digest4 = ClassicCryptoService.ED25519.sign(keypair4.getPrivKey(), "zhaoliu".getBytes());
DigitalSignatureBlob node1 = new DigitalSignatureBlob(keypair.getPubKey(), digest3);
DigitalSignatureBlob node2 = new DigitalSignatureBlob(keypair4.getPubKey(), digest4);
txRequestMessage.addNodeSignatures(node1);
txRequestMessage.addNodeSignatures(node2);
return txRequestMessage;
}
use of com.jd.blockchain.crypto.SignatureDigest in project jdchain-core by blockchain-jd-com.
the class BftsmartConsensusClientFactory method buildCredential.
@Override
public BftsmartClientAuthCredit buildCredential(SessionCredential sessionCredential, AsymmetricKeypair clientKeyPair, X509Certificate gatewayCertificate) {
if (sessionCredential == null) {
sessionCredential = BftsmartSessionCredentialConfig.createEmptyCredential();
} else if (!(sessionCredential instanceof BftsmartSessionCredential)) {
throw new IllegalArgumentException("Illegal credential info type! Requrie [" + BftsmartSessionCredential.class.getName() + "] but it is [" + sessionCredential.getClass().getName() + "]!");
}
PubKey pubKey = clientKeyPair.getPubKey();
PrivKey privKey = clientKeyPair.getPrivKey();
SignatureFunction signatureFunction = Crypto.getSignatureFunction(pubKey.getAlgorithm());
byte[] credentialBytes = BinaryProtocol.encode(sessionCredential, BftsmartSessionCredential.class);
SignatureDigest signatureDigest = signatureFunction.sign(privKey, credentialBytes);
BftsmartClientAuthCredit bftsmartClientAuthCredential = new BftsmartClientAuthCredit();
bftsmartClientAuthCredential.setSessionCredential((BftsmartSessionCredential) sessionCredential);
bftsmartClientAuthCredential.setPubKey(pubKey);
bftsmartClientAuthCredential.setSignatureDigest(signatureDigest);
bftsmartClientAuthCredential.setCertificate(null != gatewayCertificate ? CertificateUtils.toPEMString(gatewayCertificate) : null);
return bftsmartClientAuthCredential;
}
use of com.jd.blockchain.crypto.SignatureDigest in project jdchain-core by blockchain-jd-com.
the class MsgQueueClientFactory method buildCredential.
@Override
public MsgQueueClientIdentification buildCredential(SessionCredential credentialInfo, AsymmetricKeypair clientKeyPair, X509Certificate gatewayCertificate) {
MQCredentialInfo mqCredentialInfo = (MQCredentialInfo) credentialInfo;
if (null == mqCredentialInfo) {
mqCredentialInfo = MQCredentialConfig.createEmptyCredential();
}
byte[] credentialBytes = BinaryProtocol.encode(mqCredentialInfo, MQCredentialInfo.class);
PubKey pubKey = clientKeyPair.getPubKey();
// byte[] address = pubKey.toBytes(); // 使用公钥地址作为认证信息
SignatureFunction signatureFunction = Crypto.getSignatureFunction(pubKey.getAlgorithm());
SignatureDigest signatureDigest = signatureFunction.sign(clientKeyPair.getPrivKey(), credentialBytes);
MsgQueueClientIdentification mqci = new MsgQueueClientIdentification().setPubKey(clientKeyPair.getPubKey()).setIdentityInfo(mqCredentialInfo).setSignature(signatureDigest).setCertificate(gatewayCertificate != null ? CertificateUtils.toPEMString(gatewayCertificate) : null);
;
return mqci;
}
use of com.jd.blockchain.crypto.SignatureDigest in project jdchain-core by blockchain-jd-com.
the class RaftConsensusClientFactory method buildCredential.
@Override
public ClientCredential buildCredential(SessionCredential sessionCredential, AsymmetricKeypair clientKeyPair, X509Certificate gatewayCertificate) {
if (sessionCredential == null) {
sessionCredential = RaftSessionCredentialConfig.createEmptyCredential();
}
if (!(sessionCredential instanceof RaftSessionCredential)) {
throw new IllegalArgumentException("Illegal credential info type! Requrie [" + RaftSessionCredential.class.getName() + "] but it is [" + sessionCredential.getClass().getName() + "]!");
}
SignatureFunction signatureFunction = Crypto.getSignatureFunction(clientKeyPair.getAlgorithm());
byte[] credentialBytes = BinaryProtocol.encode(sessionCredential, RaftSessionCredential.class);
SignatureDigest signatureDigest = signatureFunction.sign(clientKeyPair.getPrivKey(), credentialBytes);
RaftClientCredential identification = new RaftClientCredential();
identification.setIdentityInfo(sessionCredential);
identification.setPubKey(clientKeyPair.getPubKey());
identification.setSignature(signatureDigest);
identification.setCertificate(Optional.ofNullable(gatewayCertificate).map(CertificateUtils::toPEMString).orElse(null));
return identification;
}
Aggregations