本文整理汇总了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());
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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));
}
示例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));
}
示例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));
}
示例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);
}
示例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));
}