use of io.nuls.core.crypto.ECKey in project nuls by nuls-io.
the class AccountTool method createAccount.
public static Account createAccount(String prikey) throws NulsException {
ECKey key = null;
if (StringUtils.isBlank(prikey)) {
key = new ECKey();
} else {
try {
key = ECKey.fromPrivate(new BigInteger(Hex.decode(prikey)));
} catch (Exception e) {
throw new NulsException(ErrorCode.DATA_PARSE_ERROR);
}
}
Address address = new Address(NulsContext.getInstance().getChainId(NulsContext.CHAIN_ID), Utils.sha256hash160(key.getPubKey()));
Account account = new Account();
account.setEncryptedPriKey(new byte[0]);
account.setAddress(address);
account.setPubKey(key.getPubKey());
account.setEcKey(key);
account.setPriKey(key.getPrivKeyBytes());
account.setCreateTime(TimeService.currentTimeMillis());
return account;
}
use of io.nuls.core.crypto.ECKey in project nuls by nuls-io.
the class NulsSignData method sign.
public NulsSignData sign(NulsDigestData nulsDigestData, short signAlgType, BigInteger privkey) {
if (signAlgType == NulsSignData.SIGN_ALG_ECC) {
ECKey ecKey = ECKey.fromPrivate(privkey);
byte[] signBytes = ecKey.sign(nulsDigestData.getDigestBytes(), privkey);
return new NulsSignData(signBytes);
}
return null;
}
Aggregations