Search in sources :

Example 1 with ECKey

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;
}
Also used : Account(io.nuls.account.entity.Account) Address(io.nuls.account.entity.Address) NulsException(io.nuls.core.exception.NulsException) BigInteger(java.math.BigInteger) ECKey(io.nuls.core.crypto.ECKey) NulsException(io.nuls.core.exception.NulsException) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException)

Example 2 with ECKey

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;
}
Also used : ECKey(io.nuls.core.crypto.ECKey)

Aggregations

ECKey (io.nuls.core.crypto.ECKey)2 Account (io.nuls.account.entity.Account)1 Address (io.nuls.account.entity.Address)1 NulsException (io.nuls.core.exception.NulsException)1 NulsRuntimeException (io.nuls.core.exception.NulsRuntimeException)1 BigInteger (java.math.BigInteger)1