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


Java HashFunction类代码示例

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


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

示例1: getHash

import nxt.crypto.HashFunction; //导入依赖的package包/类
public static byte[] getHash(HashFunction hashFunction, long nonce, long currencyId, long units, long counter, long accountId) {
    ByteBuffer buffer = ByteBuffer.allocate(8 + 8 + 8 + 8 + 8);
    buffer.order(ByteOrder.LITTLE_ENDIAN);
    buffer.putLong(nonce);
    buffer.putLong(currencyId);
    buffer.putLong(units);
    buffer.putLong(counter);
    buffer.putLong(accountId);
    return hashFunction.hash(buffer.array());
}
 
开发者ID:giannisKonst,项目名称:blockchain,代码行数:11,代码来源:CurrencyMinting.java

示例2: HashSolver

import nxt.crypto.HashFunction; //导入依赖的package包/类
private HashSolver(byte algorithm, long currencyId, long accountId, long counter, long units, long nonce,
                   byte[] target, int poolSize) {
    this.hashFunction = HashFunction.getHashFunction(algorithm);
    this.currencyId = currencyId;
    this.accountId = accountId;
    this.counter = counter;
    this.units = units;
    this.nonce = nonce;
    this.target = target;
    this.poolSize = poolSize;
}
 
开发者ID:giannisKonst,项目名称:blockchain,代码行数:12,代码来源:MintWorker.java

示例3: getHashFunction

import nxt.crypto.HashFunction; //导入依赖的package包/类
public static HashFunction getHashFunction(byte code) {
    try {
        HashFunction hashFunction = HashFunction.getHashFunction(code);
        if (acceptedHashFunctions.contains(hashFunction)) {
            return hashFunction;
        }
    } catch (IllegalArgumentException ignore) {}
    return null;
}
 
开发者ID:BitcoinFullnode,项目名称:ROKOS-OK-Bitcoin-Fullnode,代码行数:10,代码来源:PhasingPoll.java

示例4: processRequest

import nxt.crypto.HashFunction; //导入依赖的package包/类
@Override
JSONStreamAware processRequest(HttpServletRequest req) throws ParameterException {

    byte algorithm = ParameterParser.getByte(req, "hashAlgorithm", (byte) 0, Byte.MAX_VALUE, false);
    HashFunction hashFunction = null;
    try {
        hashFunction = HashFunction.getHashFunction(algorithm);
    } catch (IllegalArgumentException ignore) {}
    if (hashFunction == null) {
        return JSONResponses.INCORRECT_HASH_ALGORITHM;
    }

    boolean secretIsText = "true".equalsIgnoreCase(req.getParameter("secretIsText"));
    byte[] secret;
    try {
        secret = secretIsText ? Convert.toBytes(req.getParameter("secret"))
                : Convert.parseHexString(req.getParameter("secret"));
    } catch (RuntimeException e) {
        return JSONResponses.INCORRECT_SECRET;
    }
    if (secret == null || secret.length == 0) {
        return JSONResponses.MISSING_SECRET;
    }

    JSONObject response = new JSONObject();
    response.put("hash", Convert.toHexString(hashFunction.hash(secret)));
    return response;
}
 
开发者ID:BitcoinFullnode,项目名称:ROKOS-OK-Bitcoin-Fullnode,代码行数:29,代码来源:Hash.java

示例5: hashing

import nxt.crypto.HashFunction; //导入依赖的package包/类
@Test
public void hashing() {
    long nonce;
    for (nonce=0; nonce < Long.MAX_VALUE; nonce++) {
        if (CurrencyMinting.meetsTarget(CurrencyMinting.getHash(HashFunction.Keccak25.getId(), nonce, 123, 1, 1, 987),
                CurrencyMinting.getTarget(8, 16, 1, 0, 100000))) {
            break;
        }
    }
    Assert.assertEquals(149, nonce);

    for (nonce=0; nonce < Long.MAX_VALUE; nonce++) {
        if (CurrencyMinting.meetsTarget(CurrencyMinting.getHash(HashFunction.Keccak25.getId(), nonce, 123, 1, 1, 987),
                CurrencyMinting.getTarget(8, 16, 1, 100000, 100000))) {
            break;
        }
    }
    Assert.assertEquals(120597, nonce);

    for (nonce=0; nonce < Long.MAX_VALUE; nonce++) {
        if (CurrencyMinting.meetsTarget(CurrencyMinting.getHash(HashFunction.Keccak25.getId(), nonce, 123, 100, 1, 987),
                CurrencyMinting.getTarget(8, 16, 100, 0, 100000))) {
            break;
        }
    }
    Assert.assertEquals(5123, nonce);
}
 
开发者ID:BitcoinFullnode,项目名称:ROKOS-OK-Bitcoin-Fullnode,代码行数:28,代码来源:TestMintCalculations.java

示例6: sha256

import nxt.crypto.HashFunction; //导入依赖的package包/类
@Test
public void sha256() {
    byte[] hash = HashFunction.SHA256.hash(new byte[]{0x61,0x62,0x63});
    Assert.assertEquals("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", Convert.toHexString(hash));
    hash = HashFunction.SHA256.hash(new byte[]{});
    Assert.assertEquals("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", Convert.toHexString(hash));
}
 
开发者ID:BitcoinFullnode,项目名称:ROKOS-OK-Bitcoin-Fullnode,代码行数:8,代码来源:TestMintCalculations.java

示例7: sha3

import nxt.crypto.HashFunction; //导入依赖的package包/类
@Test
public void sha3() {
    byte[] hash = HashFunction.SHA3.hash(new byte[]{(byte)0x41, (byte)0xFB});
    Assert.assertEquals("A8EACEDA4D47B3281A795AD9E1EA2122B407BAF9AABCB9E18B5717B7873537D2".toLowerCase(), Convert.toHexString(hash));
    hash = HashFunction.SHA3.hash(new byte[]{});
    Assert.assertEquals("c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470", Convert.toHexString(hash));
}
 
开发者ID:BitcoinFullnode,项目名称:ROKOS-OK-Bitcoin-Fullnode,代码行数:8,代码来源:TestMintCalculations.java

示例8: scrypt

import nxt.crypto.HashFunction; //导入依赖的package包/类
@Test
public void scrypt() {
    byte[] hash = HashFunction.SCRYPT.hash(new byte[]{(byte) 0x41, (byte) 0xFB});
    Assert.assertEquals("da3f4f010d772567a8896465d11df28693b244c91b8ba4bea5a30f6be572b667".toLowerCase(), Convert.toHexString(hash));
    hash = HashFunction.SCRYPT.hash(new byte[]{});
    Assert.assertEquals("0cf2967ca5c120e80b37f8f75c971842e05da107278c1058e6ffbc68911c11f1", Convert.toHexString(hash));
}
 
开发者ID:BitcoinFullnode,项目名称:ROKOS-OK-Bitcoin-Fullnode,代码行数:8,代码来源:TestMintCalculations.java

示例9: mint

import nxt.crypto.HashFunction; //导入依赖的package包/类
@Test
public void mint() {
    APICall apiCall = new TestCurrencyIssuance.Builder().
            type(CurrencyType.MINTABLE.getCode() | CurrencyType.EXCHANGEABLE.getCode()).
            maxSupply((long)10000000).
            initialSupply((long)0).
            issuanceHeight(0).
            minting((byte)2, (byte)8, HashFunction.SHA256.getId()).
            build();

    String currencyId = TestCurrencyIssuance.issueCurrencyApi(apiCall);
    mintCurrency(currencyId);
}
 
开发者ID:BitcoinFullnode,项目名称:ROKOS-OK-Bitcoin-Fullnode,代码行数:14,代码来源:TestCurrencyMint.java

示例10: verifySecret

import nxt.crypto.HashFunction; //导入依赖的package包/类
public boolean verifySecret(byte[] revealedSecret) {
    HashFunction hashFunction = getHashFunction(algorithm);
    return hashFunction != null && Arrays.equals(hashedSecret, hashFunction.hash(revealedSecret));
}
 
开发者ID:BitcoinFullnode,项目名称:ROKOS-OK-Bitcoin-Fullnode,代码行数:5,代码来源:PhasingPoll.java


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