All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jd.blockchain.ledger.BlockchainKeyGenerator Maven / Gradle / Ivy

There is a newer version: 1.6.5.RELEASE
Show newest version
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