use of com.jd.blockchain.crypto.CryptoProvider in project jdchain-core by blockchain-jd-com.
the class MerkleHashDataSetTest method createCryptoSetting.
private CryptoSetting createCryptoSetting() {
CryptoProvider[] supportedProviders = new CryptoProvider[SUPPORTED_PROVIDERS.length];
for (int i = 0; i < SUPPORTED_PROVIDERS.length; i++) {
supportedProviders[i] = Crypto.getProvider(SUPPORTED_PROVIDERS[i]);
}
CryptoConfig cryptoConfig = new CryptoConfig();
cryptoConfig.setSupportedProviders(supportedProviders);
cryptoConfig.setHashAlgorithm(ClassicAlgorithm.SHA256);
cryptoConfig.setAutoVerifyHash(true);
return cryptoConfig;
}
use of com.jd.blockchain.crypto.CryptoProvider in project jdchain-core by blockchain-jd-com.
the class LedgerInitConfiguration method createCryptoConfig.
private static CryptoConfig createCryptoConfig(CryptoProperties cryptoProperties) {
Set<String> cryptoProviderNames = new LinkedHashSet<String>();
if (cryptoProperties.getProviders() != null) {
for (String providerName : cryptoProperties.getProviders()) {
cryptoProviderNames.add(providerName);
}
}
CryptoProvider[] cryptoProviders = new CryptoProvider[cryptoProviderNames.size()];
int i = 0;
for (String providerName : cryptoProviderNames) {
cryptoProviders[i] = Crypto.getProvider(providerName);
i++;
}
String hashAlgorithmName = StringUtils.trim(cryptoProperties.getHashAlgorithm());
hashAlgorithmName = hashAlgorithmName.length() == 0 ? DEFAULT_HASH_ALGORITHM : hashAlgorithmName;
CryptoAlgorithm hashAlgorithm = Crypto.getAlgorithm(hashAlgorithmName);
CryptoConfig cryptoConfig = new CryptoConfig();
cryptoConfig.setSupportedProviders(cryptoProviders);
cryptoConfig.setAutoVerifyHash(cryptoProperties.isVerifyHash());
cryptoConfig.setHashAlgorithm(hashAlgorithm);
return cryptoConfig;
}
use of com.jd.blockchain.crypto.CryptoProvider in project jdchain-core by blockchain-jd-com.
the class CryptoConfig method setSupportedProviders.
public void setSupportedProviders(CryptoProvider[] supportedProviders) {
HashMap<String, CryptoProvider> providers = new HashMap<String, CryptoProvider>();
HashMap<String, CryptoAlgorithm> nameAlgorithms = new HashMap<String, CryptoAlgorithm>();
HashMap<Short, CryptoAlgorithm> codeAlgorithms = new HashMap<Short, CryptoAlgorithm>();
if (supportedProviders != null) {
// 检查是否存在重复的提供者以及算法;
for (CryptoProvider cryptoProvider : supportedProviders) {
if (providers.containsKey(cryptoProvider.getName())) {
throw new LedgerException("Duplicate crypto providers [" + cryptoProvider.getName() + "]!");
}
CryptoAlgorithm[] algorithms = cryptoProvider.getAlgorithms();
for (CryptoAlgorithm alg : algorithms) {
if (nameAlgorithms.containsKey(alg.name())) {
throw new LedgerException("Duplicate crypto algorithms [" + alg.toString() + "] from provider " + cryptoProvider.getName() + "!");
}
if (codeAlgorithms.containsKey(alg.code())) {
throw new LedgerException("Duplicate crypto algorithms [" + alg.toString() + "] from provider" + cryptoProvider.getName() + "!");
}
nameAlgorithms.put(alg.name(), alg);
codeAlgorithms.put(alg.code(), alg);
}
providers.put(cryptoProvider.getName(), cryptoProvider);
}
}
this.providers = providers;
this.nameAlgorithms = nameAlgorithms;
this.codeAlgorithms = codeAlgorithms;
this.cryptoProviders = supportedProviders;
}
Aggregations