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


Java Hash类代码示例

本文整理汇总了Java中org.hyperledger.common.Hash的典型用法代码示例。如果您正苦于以下问题:Java Hash类的具体用法?Java Hash怎么用?Java Hash使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: BlockRepresentation

import org.hyperledger.common.Hash; //导入依赖的package包/类
public BlockRepresentation(BID id,
                           BID previousID,
                           int height,
                           LocalTime localCreateTime,
                           int nonce,
                           int version,
                           Hash merkleRoot,
                           int difficultyTarget,
                           List<TID> transactions) {
    this.id = id;
    this.previousID = previousID;
    this.height = height;
    this.localCreateTime = localCreateTime;
    this.nonce = nonce;
    this.version = version;
    this.merkleRoot = merkleRoot;
    this.difficultyTarget = difficultyTarget;
    this.transactions = transactions;
}
 
开发者ID:DigitalAssetCom,项目名称:-deprecated-hlp-candidate,代码行数:20,代码来源:BlockRepresentation.java

示例2: fromSatoshiStyle

import org.hyperledger.common.Hash; //导入依赖的package包/类
/**
 * Convert a human readable address string to an address object
 * This conversion supports COMMON and P2SH address types only.
 *
 * @param address - the human readable address
 * @return an address object with type and network ad encoded in the readable string
 * @throws HyperLedgerException - for malformed address strings
 */
public static UIAddress fromSatoshiStyle(String address) throws HyperLedgerException {
    try {
        Network network = Network.PRODUCTION;
        Address.Type type = Address.Type.COMMON;
        byte[] raw = ByteUtils.fromBase58(address);
        if ((raw[0] & 0xff) == 0x0) {
            network = Network.PRODUCTION;
            type = Address.Type.COMMON;
        }
        if ((raw[0] & 0xff) == 5) {
            network = Network.PRODUCTION;
            type = Address.Type.P2SH;
        }
        if ((raw[0] & 0xff) == 0x6f) {
            network = Network.TEST;
            type = Address.Type.COMMON;
        }
        if ((raw[0] & 0xff) == 196) {
            network = Network.TEST;
            type = Address.Type.P2SH;
        }
        byte[] check = Hash.hash(raw, 0, raw.length - 4);
        for (int i = 0; i < 4; ++i) {
            if (check[i] != raw[raw.length - 4 + i]) {
                throw new HyperLedgerException("Address checksum mismatch");
            }
        }
        byte[] keyDigest = new byte[raw.length - 5];
        System.arraycopy(raw, 1, keyDigest, 0, raw.length - 5);
        return new UIAddress(network, type, keyDigest);
    } catch (Exception e) {
        throw new HyperLedgerException(e);
    }
}
 
开发者ID:DigitalAssetCom,项目名称:-deprecated-hlp-candidate,代码行数:43,代码来源:UIAddress.java

示例3: toString

import org.hyperledger.common.Hash; //导入依赖的package包/类
/**
 * @return Human readable serialization of a COMMON or P2SH address that uses network conventions.
 */
public String toString() {
    byte[] keyDigest = address.toByteArray();
    int addressFlag;
    if (network == Network.TEST) {
        if (address.getType() == Address.Type.COMMON) {
            addressFlag = 0x6f;
        } else if (address.getType() == Address.Type.P2SH) {
            addressFlag = 196;
        } else {
            return address.getType().name() + ":" + ByteUtils.toHex(address.toByteArray());
        }
    } else {
        if (address.getType() == Address.Type.COMMON) {
            addressFlag = 0x0;
        } else if (address.getType() == Address.Type.P2SH) {
            addressFlag = 0x5;
        } else {
            return address.getType().name() + ":" + ByteUtils.toHex(address.toByteArray());
        }
    }
    byte[] addressBytes = new byte[1 + keyDigest.length + 4];
    addressBytes[0] = (byte) (addressFlag & 0xff);
    System.arraycopy(keyDigest, 0, addressBytes, 1, keyDigest.length);
    byte[] check = Hash.hash(addressBytes, 0, keyDigest.length + 1);
    System.arraycopy(check, 0, addressBytes, keyDigest.length + 1, 4);
    return ByteUtils.toBase58(addressBytes);
}
 
开发者ID:DigitalAssetCom,项目名称:-deprecated-hlp-candidate,代码行数:31,代码来源:UIAddress.java

示例4: decode

import org.hyperledger.common.Hash; //导入依赖的package包/类
public static byte[] decode(String mnemonic, String salt) throws HyperLedgerException {
    StringTokenizer tokenizer = new StringTokenizer(mnemonic);
    int nt = tokenizer.countTokens();
    if (nt % 6 != 0) {
        throw new HyperLedgerException("invalid mnemonic - word cound not divisible by 6");
    }
    boolean[] bits = new boolean[11 * nt];
    int i = 0;
    while (tokenizer.hasMoreElements()) {
        int c = Arrays.binarySearch(english, tokenizer.nextToken());
        for (int j = 0; j < 11; ++j) {
            bits[i++] = (c & (1 << (10 - j))) > 0;
        }
    }
    byte[] data = new byte[bits.length / 33 * 4];
    for (i = 0; i < bits.length / 33 * 32; ++i) {
        data[i / 8] |= (bits[i] ? 1 : 0) << (7 - (i % 8));
    }
    byte[] check = Hash.sha256(data);
    for (i = bits.length / 33 * 32; i < bits.length; ++i) {
        if ((check[(i - bits.length / 33 * 32) / 8] & (1 << (7 - (i % 8))) ^ (bits[i] ? 1 : 0) << (7 - (i % 8))) != 0) {
            throw new HyperLedgerException("invalid mnemonic - checksum failed");
        }
    }
    try {
        SecretKey seedkey = new SecretKeySpec(("mnemonic" + salt).getBytes("UTF-8"), "Blowfish");
        Cipher cipher = Cipher.getInstance("BlowFish/ECB/NoPadding", "BC");
        cipher.init(Cipher.DECRYPT_MODE, seedkey);
        for (i = 0; i < 1000; ++i) {
            data = cipher.doFinal(data);
        }
    } catch (UnsupportedEncodingException | NoSuchAlgorithmException |
            NoSuchProviderException | NoSuchPaddingException | InvalidKeyException | IllegalBlockSizeException | BadPaddingException e) {
        throw new HyperLedgerException("can not decrypt mnemonic", e);
    }
    return data;
}
 
开发者ID:DigitalAssetCom,项目名称:-deprecated-hlp-candidate,代码行数:38,代码来源:Mnemonic.java

示例5: getMnemonic

import org.hyperledger.common.Hash; //导入依赖的package包/类
public static String getMnemonic(byte[] data) throws HyperLedgerException {
    if (data.length % 4 != 0) {
        throw new HyperLedgerException("Invalid data length for mnemonic");
    }
    byte[] check = Hash.sha256(data);

    boolean[] bits = new boolean[data.length * 8 + data.length / 4];

    for (int i = 0; i < data.length; i++) {
        for (int j = 0; j < 8; j++) {
            bits[8 * i + j] = (data[i] & (1 << (7 - j))) > 0;
        }
    }
    for (int i = 0; i < data.length / 4; i++) {
        bits[8 * data.length + i] = (check[i / 8] & (1 << (7 - (i % 8)))) > 0;
    }

    int mlen = data.length * 3 / 4;
    StringBuilder mnemo = new StringBuilder();
    for (int i = 0; i < mlen; i++) {
        int idx = 0;
        for (int j = 0; j < 11; j++) {
            idx += (bits[i * 11 + j] ? 1 : 0) << (10 - j);
        }
        mnemo.append(english[idx]);
        if (i < mlen - 1) {
            mnemo.append(" ");
        }
    }
    return mnemo.toString();
}
 
开发者ID:DigitalAssetCom,项目名称:-deprecated-hlp-candidate,代码行数:32,代码来源:Mnemonic.java

示例6: deserialize

import org.hyperledger.common.Hash; //导入依赖的package包/类
@Override
public Hash deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    JsonToken t = jp.getCurrentToken();
    if (t == JsonToken.VALUE_STRING) {
        String hashString = jp.getText().trim();
        if (hashString.length() == 0) {
            return null;
        }

        return new Hash(hashString);
    }

    throw ctxt.mappingException(handledType());
}
 
开发者ID:DigitalAssetCom,项目名称:-deprecated-hlp-candidate,代码行数:15,代码来源:HashDeserializer.java

示例7: mergeWithItself

import org.hyperledger.common.Hash; //导入依赖的package包/类
private static Hash mergeWithItself(MerkleTreeNode left, int count) {
    Hash hash = left.getID();
    for (int i = 0; i < count; i++) {
        hash = Hash.merge(hash, hash);
    }
    return hash;
}
 
开发者ID:hyperledger-archives,项目名称:fabric-api-archive,代码行数:8,代码来源:MerkleTree.java

示例8: Transaction

import org.hyperledger.common.Hash; //导入依赖的package包/类
public Transaction(List<TID> inputs, List<byte[]> outputs, List<Endorser> endorsers) {
    this.inputs = inputs;
    this.outputs = outputs;
    this.endorsers = endorsers;

    this.ID = new TID(Hash.of(fabricInvocationForm()));
}
 
开发者ID:hyperledger-archives,项目名称:fabric-api-archive,代码行数:8,代码来源:Transaction.java

示例9: build

import org.hyperledger.common.Hash; //导入依赖的package包/类
public Transaction build() {
    for (PrivateKey key : endorserKeys) {
        Endorser endorser = Endorser.create(Hash.of(outputs.get(0)).toByteArray(), key);
        endorsers.add(endorser);
    }
    return new Transaction(inputs, outputs, endorsers);
}
 
开发者ID:hyperledger-archives,项目名称:fabric-api-archive,代码行数:8,代码来源:TransactionBuilder.java

示例10: HashSerializer

import org.hyperledger.common.Hash; //导入依赖的package包/类
public HashSerializer() {
    super(Hash.class);
}
 
开发者ID:DigitalAssetCom,项目名称:-deprecated-hlp-candidate,代码行数:4,代码来源:HashSerializer.java

示例11: serialize

import org.hyperledger.common.Hash; //导入依赖的package包/类
@Override
public void serialize(Hash value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
    jgen.writeString(value.toString());
}
 
开发者ID:DigitalAssetCom,项目名称:-deprecated-hlp-candidate,代码行数:5,代码来源:HashSerializer.java

示例12: HashDeserializer

import org.hyperledger.common.Hash; //导入依赖的package包/类
protected HashDeserializer() {
    super(Hash.class);
}
 
开发者ID:DigitalAssetCom,项目名称:-deprecated-hlp-candidate,代码行数:4,代码来源:HashDeserializer.java

示例13: Rejected

import org.hyperledger.common.Hash; //导入依赖的package包/类
public Rejected(String command, Hash hash, int code) {
    super(hash);
    this.command = command;
    this.code = code;
}
 
开发者ID:DigitalAssetCom,项目名称:-deprecated-hlp-candidate,代码行数:6,代码来源:ClientEventQueue.java

示例14: compress

import org.hyperledger.common.Hash; //导入依赖的package包/类
/**
 * Compress a merkle tree into the smallest possible representation that
 * does not lose information on nodes that are not instances of PrunedNode
 *
 * @param nodes list of nodes to compress
 * @return root digest
 * @see PrunedNode
 */
public static List<MerkleTreeNode> compress(List<MerkleTreeNode> nodes) {
    List<MerkleTreeNode> result = new ArrayList<>(nodes);
    boolean hasChanged;
    do {
        if (result.size() <= 1) return result;
        hasChanged = false;
        int leftPos, rightPos;
        List<MerkleTreeNode> source = result;
        result = new ArrayList<>();
        int prevPos = -twoPower(source.get(0).getMerkleHeight());
        for (int i = 0; i < source.size(); i++) {
            MerkleTreeNode left = source.get(i);
            leftPos = prevPos + twoPower(left.getMerkleHeight());
            // if 'left' node is the last so it is without 'right' node
            if (i == source.size() - 1) {
                result.add(left);
                prevPos = leftPos;
                continue;
            }
            MerkleTreeNode right = source.get(i + 1);
            rightPos = leftPos + twoPower(left.getMerkleHeight());

            if (isMergeableDistantPrunedNeighbours(left, leftPos, right, rightPos)) {
                result.add(new PrunedNode(
                        Hash.merge(left.getID(), mergeWithItself(right, left.getMerkleHeight() - right.getMerkleHeight())),
                        left.getMerkleHeight() + 1));
                hasChanged = true;
                i++;
            } else if (isNeighbours(left, leftPos, right, rightPos)) {
                if (left instanceof PrunedNode && right instanceof PrunedNode) {
                    result.add(new PrunedNode(Hash.merge(left.getID(), right.getID()), left.getMerkleHeight() + 1));
                    prevPos = rightPos;
                    hasChanged = true;
                    i++;
                } else {
                    result.add(left);
                    result.add(right);
                    prevPos = rightPos;
                    i++;
                }
            } else {
                result.add(left);
                prevPos = leftPos;
            }
        }
    } while (hasChanged);
    return result;
}
 
开发者ID:hyperledger-archives,项目名称:fabric-api-archive,代码行数:57,代码来源:MerkleTree.java

示例15: getID

import org.hyperledger.common.Hash; //导入依赖的package包/类
@Override
public Hash getID() {
    return hash;
}
 
开发者ID:hyperledger-archives,项目名称:fabric-api-archive,代码行数:5,代码来源:PrunedNode.java


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