当前位置: 首页>>代码示例>>Java>>正文


Java Convert.toHexString方法代码示例

本文整理汇总了Java中nxt.util.Convert.toHexString方法的典型用法代码示例。如果您正苦于以下问题:Java Convert.toHexString方法的具体用法?Java Convert.toHexString怎么用?Java Convert.toHexString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在nxt.util.Convert的用法示例。


在下文中一共展示了Convert.toHexString方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: processRequest

import nxt.util.Convert; //导入方法依赖的package包/类
@Override
JSONStreamAware processRequest(HttpServletRequest req) {

    long accountId;
    String secretPhrase = Convert.emptyToNull(req.getParameter("secretPhrase"));
    String publicKeyString = Convert.emptyToNull(req.getParameter("publicKey"));
    if (secretPhrase != null) {
        byte[] publicKey = Crypto.getPublicKey(secretPhrase);
        accountId = Account.getId(publicKey);
        publicKeyString = Convert.toHexString(publicKey);
    } else if (publicKeyString != null) {
        accountId = Account.getId(Convert.parseHexString(publicKeyString));
    } else {
        return MISSING_SECRET_PHRASE_OR_PUBLIC_KEY;
    }

    JSONObject response = new JSONObject();
    JSONData.putAccount(response, "account", accountId);
    response.put("publicKey", publicKeyString);

    return response;
}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:23,代码来源:GetAccountId.java

示例2: validate

import nxt.util.Convert; //导入方法依赖的package包/类
@Override
void validate(Transaction transaction) throws NxtException.ValidationException {
    if (! transaction.getType().hasRecipient()) {
        throw new NxtException.NotValidException("PublicKeyAnnouncement cannot be attached to transactions with no recipient");
    }
    if (publicKey.length != 32) {
        throw new NxtException.NotValidException("Invalid recipient public key length: " + Convert.toHexString(publicKey));
    }
    long recipientId = transaction.getRecipientId();
    if (Account.getId(this.publicKey) != recipientId) {
        throw new NxtException.NotValidException("Announced public key does not match recipient accountId");
    }
    if (transaction.getVersion() == 0) {
        throw new NxtException.NotValidException("Public key announcements not enabled for version 0 transactions");
    }
    Account recipientAccount = Account.getAccount(recipientId);
    if (recipientAccount != null && recipientAccount.getPublicKey() != null && ! Arrays.equals(publicKey, recipientAccount.getPublicKey())) {
        throw new NxtException.NotCurrentlyValidException("A different public key for this account has already been announced");
    }
}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:21,代码来源:Appendix.java

示例3: getAccount

import nxt.util.Convert; //导入方法依赖的package包/类
public static Account getAccount(byte[] publicKey) {
    Account account = accountTable.get(accountDbKeyFactory.newKey(getId(publicKey)));
    if (account == null) {
        return null;
    }
    if (account.getPublicKey() == null || Arrays.equals(account.getPublicKey(), publicKey)) {
        return account;
    }
    throw new RuntimeException("DUPLICATE KEY for account " + Convert.toUnsignedLong(account.getId())
            + " existing key " + Convert.toHexString(account.getPublicKey()) + " new key " + Convert.toHexString(publicKey));
}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:12,代码来源:Account.java

示例4: generateHallmark

import nxt.util.Convert; //导入方法依赖的package包/类
public static String generateHallmark(String secretPhrase, String host, int weight, int date) {

        if (host.length() == 0 || host.length() > 100) {
            throw new IllegalArgumentException("Hostname length should be between 1 and 100");
        }
        if (weight <= 0 || weight > Constants.MAX_BALANCE_NXT) {
            throw new IllegalArgumentException("Weight should be between 1 and " + Constants.MAX_BALANCE_NXT);
        }

        byte[] publicKey = Crypto.getPublicKey(secretPhrase);
        byte[] hostBytes = Convert.toBytes(host);

        ByteBuffer buffer = ByteBuffer.allocate(32 + 2 + hostBytes.length + 4 + 4 + 1);
        buffer.order(ByteOrder.LITTLE_ENDIAN);
        buffer.put(publicKey);
        buffer.putShort((short)hostBytes.length);
        buffer.put(hostBytes);
        buffer.putInt(weight);
        buffer.putInt(date);

        byte[] data = buffer.array();
        data[data.length - 1] = (byte) ThreadLocalRandom.current().nextInt();
        byte[] signature = Crypto.sign(data, secretPhrase);

        return Convert.toHexString(data) + Convert.toHexString(signature);

    }
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:28,代码来源:Hallmark.java

示例5: parseTransaction

import nxt.util.Convert; //导入方法依赖的package包/类
static TransactionImpl parseTransaction(byte[] bytes) throws NxtException.ValidationException {
    try {
        ByteBuffer buffer = ByteBuffer.wrap(bytes);
        buffer.order(ByteOrder.LITTLE_ENDIAN);
        byte type = buffer.get();
        byte subtype = buffer.get();
        byte version = (byte) ((subtype & 0xF0) >> 4);
        subtype = (byte) (subtype & 0x0F);
        int timestamp = buffer.getInt();
        short deadline = buffer.getShort();
        byte[] senderPublicKey = new byte[32];
        buffer.get(senderPublicKey);
        long recipientId = buffer.getLong();
        long amountNQT = buffer.getLong();
        long feeNQT = buffer.getLong();
        String referencedTransactionFullHash = null;
        byte[] referencedTransactionFullHashBytes = new byte[32];
        buffer.get(referencedTransactionFullHashBytes);
        if (Convert.emptyToNull(referencedTransactionFullHashBytes) != null) {
            referencedTransactionFullHash = Convert.toHexString(referencedTransactionFullHashBytes);
        }
        byte[] signature = new byte[64];
        buffer.get(signature);
        signature = Convert.emptyToNull(signature);
        int flags = 0;
        int ecBlockHeight = 0;
        long ecBlockId = 0;
        if (version > 0) {
            flags = buffer.getInt();
            ecBlockHeight = buffer.getInt();
            ecBlockId = buffer.getLong();
        }
        TransactionType transactionType = TransactionType.findTransactionType(type, subtype);
        TransactionImpl.BuilderImpl builder = new TransactionImpl.BuilderImpl(version, senderPublicKey, amountNQT, feeNQT,
                timestamp, deadline, transactionType.parseAttachment(buffer, version))
                .referencedTransactionFullHash(referencedTransactionFullHash)
                .signature(signature)
                .ecBlockHeight(ecBlockHeight)
                .ecBlockId(ecBlockId);
        if (transactionType.hasRecipient()) {
            builder.recipientId(recipientId);
        }
        int position = 1;
        if ((flags & position) != 0 || (version == 0 && transactionType == TransactionType.Messaging.ARBITRARY_MESSAGE)) {
            builder.message(new Appendix.Message(buffer, version));
        }
        position <<= 1;
        if ((flags & position) != 0) {
            builder.encryptedMessage(new Appendix.EncryptedMessage(buffer, version));
        }
        position <<= 1;
        if ((flags & position) != 0) {
            builder.publicKeyAnnouncement(new Appendix.PublicKeyAnnouncement(buffer, version));
        }
        position <<= 1;
        if ((flags & position) != 0) {
            builder.encryptToSelfMessage(new Appendix.EncryptToSelfMessage(buffer, version));
        }
        return builder.build();
    } catch (NxtException.NotValidException|RuntimeException e) {
        Logger.logDebugMessage("Failed to parse transaction bytes: " + Convert.toHexString(bytes));
        throw e;
    }
}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:65,代码来源:TransactionImpl.java


注:本文中的nxt.util.Convert.toHexString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。