com.jd.blockchain.ledger.BlockchainKeyGenerator Maven / Gradle / Ivy
package com.jd.blockchain.ledger;
import com.jd.blockchain.crypto.CryptoAlgorithm;
import com.jd.blockchain.crypto.AsymmetricKeypair;
import com.jd.blockchain.crypto.Crypto;
import com.jd.blockchain.crypto.SignatureFunction;
/**
* 区块链密钥生成器;
*
* @author huanghaiquan
*
*/
public class BlockchainKeyGenerator {
public static final String DEFAULT_ALGORITHM = "ED25519";
private BlockchainKeyGenerator() {
}
public static BlockchainKeyGenerator getInstance() {
return new BlockchainKeyGenerator();
}
public BlockchainKeypair generate() {
return generate(DEFAULT_ALGORITHM);
}
public BlockchainKeypair generate(String algorithmName) {
CryptoAlgorithm algorithm = Crypto.getAlgorithm(algorithmName);
return generate(algorithm);
}
public BlockchainKeypair generate(CryptoAlgorithm signatureAlgorithm) {
SignatureFunction signFunc = Crypto.getSignatureFunction(signatureAlgorithm);
AsymmetricKeypair cryptoKeyPair = signFunc.generateKeypair();
return new BlockchainKeypair(cryptoKeyPair.getPubKey(), cryptoKeyPair.getPrivKey());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy