本文整理汇总了Java中org.spongycastle.util.Arrays.concatenate方法的典型用法代码示例。如果您正苦于以下问题:Java Arrays.concatenate方法的具体用法?Java Arrays.concatenate怎么用?Java Arrays.concatenate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.spongycastle.util.Arrays
的用法示例。
在下文中一共展示了Arrays.concatenate方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: compressCoinbase
import org.spongycastle.util.Arrays; //导入方法依赖的package包/类
public static byte[] compressCoinbase(byte[] bitcoinMergedMiningCoinbaseTransactionSerialized, boolean lastOcurrence) {
List<Byte> coinBaseTransactionSerializedAsList = java.util.Arrays.asList(ArrayUtils.toObject(bitcoinMergedMiningCoinbaseTransactionSerialized));
List<Byte> tagAsList = java.util.Arrays.asList(ArrayUtils.toObject(RskMiningConstants.RSK_TAG));
int rskTagPosition;
if (lastOcurrence) {
rskTagPosition = Collections.lastIndexOfSubList(coinBaseTransactionSerializedAsList, tagAsList);
} else {
rskTagPosition = Collections.indexOfSubList(coinBaseTransactionSerializedAsList, tagAsList);
}
int remainingByteCount = bitcoinMergedMiningCoinbaseTransactionSerialized.length - rskTagPosition - RskMiningConstants.RSK_TAG.length - RskMiningConstants.BLOCK_HEADER_HASH_SIZE;
if (remainingByteCount > RskMiningConstants.MAX_BYTES_AFTER_MERGED_MINING_HASH) {
throw new IllegalArgumentException("More than 128 bytes after RSK tag");
}
int sha256Blocks = rskTagPosition / 64;
int bytesToHash = sha256Blocks * 64;
SHA256Digest digest = new SHA256Digest();
digest.update(bitcoinMergedMiningCoinbaseTransactionSerialized, 0, bytesToHash);
byte[] hashedContent = digest.getEncodedState();
byte[] trimmedHashedContent = new byte[RskMiningConstants.MIDSTATE_SIZE_TRIMMED];
System.arraycopy(hashedContent, 8, trimmedHashedContent, 0, RskMiningConstants.MIDSTATE_SIZE_TRIMMED);
byte[] unHashedContent = new byte[bitcoinMergedMiningCoinbaseTransactionSerialized.length - bytesToHash];
System.arraycopy(bitcoinMergedMiningCoinbaseTransactionSerialized, bytesToHash, unHashedContent, 0, unHashedContent.length);
return Arrays.concatenate(trimmedHashedContent, unHashedContent);
}
示例2: getBitcoinMergedMiningCoinbaseTransaction
import org.spongycastle.util.Arrays; //导入方法依赖的package包/类
public static co.rsk.bitcoinj.core.BtcTransaction getBitcoinMergedMiningCoinbaseTransaction(co.rsk.bitcoinj.core.NetworkParameters params, byte[] blockHashForMergedMining) {
co.rsk.bitcoinj.core.BtcTransaction coinbaseTransaction = new co.rsk.bitcoinj.core.BtcTransaction(params);
//Add a random number of random bytes before the RSK tag
SecureRandom random = new SecureRandom();
byte[] prefix = new byte[random.nextInt(1000)];
random.nextBytes(prefix);
byte[] bytes = Arrays.concatenate(prefix, RskMiningConstants.RSK_TAG, blockHashForMergedMining);
// Add the Tag to the scriptSig of first input
co.rsk.bitcoinj.core.TransactionInput ti = new co.rsk.bitcoinj.core.TransactionInput(params, coinbaseTransaction, bytes);
coinbaseTransaction.addInput(ti);
ByteArrayOutputStream scriptPubKeyBytes = new ByteArrayOutputStream();
co.rsk.bitcoinj.core.BtcECKey key = new co.rsk.bitcoinj.core.BtcECKey();
try {
co.rsk.bitcoinj.script.Script.writeBytes(scriptPubKeyBytes, key.getPubKey());
} catch (IOException e) {
throw new RuntimeException(e);
}
scriptPubKeyBytes.write(co.rsk.bitcoinj.script.ScriptOpCodes.OP_CHECKSIG);
coinbaseTransaction.addOutput(new co.rsk.bitcoinj.core.TransactionOutput(params, coinbaseTransaction, co.rsk.bitcoinj.core.Coin.valueOf(50, 0), scriptPubKeyBytes.toByteArray()));
return coinbaseTransaction;
}
示例3: encrypt
import org.spongycastle.util.Arrays; //导入方法依赖的package包/类
public EncryptedMessage encrypt(String message) throws
InvalidAlgorithmParameterException, InvalidKeyException,
BadPaddingException, IllegalBlockSizeException, UnsupportedEncodingException,
InvalidCipherTextException, NoSuchAlgorithmException {
this.iv = new byte[IVBYTES];
random.nextBytes(this.iv);
CipherParameters ivAndKey = new ParametersWithIV(new KeyParameter(aesKey), this.iv);
encryptCipher.init(true, ivAndKey);
byte[] es = cipherData(encryptCipher, message.getBytes(UTF_8));
Mac hmac = Mac.getInstance("HmacSHA256");
hmac.init(this.hmacSecretKey);
byte[] digest = hmac.doFinal(Arrays.concatenate(this.iv, es));
byte[] ciphertext = Arrays.concatenate(es, digest);
EncryptedMessage encrypted = new EncryptedMessage();
encrypted.ciphertext = Hex.encode(ciphertext);
encrypted.iv = Hex.encode(this.iv);
encrypted.salt = Hex.encode(this.salt);
encrypted.iterations = iterations;
return encrypted;
}
示例4: mine
import org.spongycastle.util.Arrays; //导入方法依赖的package包/类
/**
* Adds a nonce to given block which complies with the given difficulty
*
* For the PoC series, we use a simplified proof-of-work.
* This is not ASIC resistant and is meant merely as a placeholder.
* It utilizes the bare SHA3 hash function to secure the block chain by requiring
* the SHA3 hash of the concatenation of the nonce and the header’s SHA3 hash to be
* sufficiently low. It is formally defined as PoW:
*
* PoW(H, n) ≡ BE(SHA3(SHA3(RLP(H!n)) ◦ n))
*
* where:
* RLP(H!n) is the RLP encoding of the block header H, not including the
* final nonce component;
* SHA3 is the SHA3 hash function accepting an arbitrary length series of
* bytes and evaluating to a series of 32 bytes (i.e. 256-bit);
* n is the nonce, a series of 32 bytes;
* o is the series concatenation operator;
* BE(X) evaluates to the value equal to X when interpreted as a
* big-endian-encoded integer.
*
* @param newBlock without a valid nonce
* @param difficulty - the mining difficulty
* @return true if valid nonce has been added to the block
*/
public boolean mine(Block newBlock, byte[] difficulty) {
// eval(_root, _nonce) <= (bigint(1) << 256) / _difficulty; }
stop = false;
BigInteger max = BigInteger.valueOf(2).pow(255);
byte[] target = BigIntegers.asUnsignedByteArray(32,
max.divide(new BigInteger(1, difficulty)));
long newGasLimit = Math.max(125000,
(new BigInteger(1, newBlock.getGasLimit()).longValue() * (1024 - 1) + (newBlock.getGasUsed() * 6 / 5)) / 1024);
newBlock.getHeader().setGasLimit(BigInteger.valueOf(newGasLimit).toByteArray());
byte[] hash = HashUtil.sha3(newBlock.getEncodedWithoutNonce());
byte[] testNonce = new byte[32];
byte[] concat;
while (ByteUtil.increment(testNonce) && !stop) {
if (testNonce[31] == 0 && testNonce[30] == 0) {
System.out.println("mining: " + new BigInteger(1, testNonce));
}
if (testNonce[31] == 0)
sleep();
concat = Arrays.concatenate(hash, testNonce);
byte[] result = HashUtil.sha3(concat);
if (FastByteComparisons.compareTo(result, 0, 32, target, 0, 32) < 0) {
newBlock.setNonce(testNonce);
return true;
}
}
return false; // couldn't find a valid nonce
}
示例5: calcPowValue
import org.spongycastle.util.Arrays; //导入方法依赖的package包/类
public byte[] calcPowValue() {
// nonce bytes are expected in Little Endian order, reverting
byte[] nonceReverted = Arrays.reverse(nonce);
byte[] hashWithoutNonce = HashUtil.sha3(getEncodedWithoutNonce());
byte[] seed = Arrays.concatenate(hashWithoutNonce, nonceReverted);
byte[] seedHash = HashUtil.sha512(seed);
byte[] concat = Arrays.concatenate(seedHash, mixHash);
return HashUtil.sha3(concat);
}
示例6: mine
import org.spongycastle.util.Arrays; //导入方法依赖的package包/类
/**
* Adds a nonce to given block which complies with the given difficulty
*
* For the PoC series, we use a simplified proof-of-work.
* This is not ASIC resistant and is meant merely as a placeholder.
* It utilizes the bare SHA3 hash function to secure the block chain by requiring
* the SHA3 hash of the concatenation of the nonce and the header’s SHA3 hash to be
* sufficiently low. It is formally defined as PoW:
*
* PoW(H, n) ≡ BE(SHA3(SHA3(RLP(H!n)) ◦ n))
*
* where:
* RLP(H!n) is the RLP encoding of the block header H, not including the
* final nonce component;
* SHA3 is the SHA3 hash function accepting an arbitrary length series of
* bytes and evaluating to a series of 32 bytes (i.e. 256-bit);
* n is the nonce, a series of 32 bytes;
* o is the series concatenation operator;
* BE(X) evaluates to the value equal to X when interpreted as a
* big-endian-encoded integer.
*
* @param newBlock without a valid nonce
* @param difficulty - the mining difficulty
* @return true if valid nonce has been added to the block
*/
public boolean mine(Block newBlock, byte[] difficulty) {
// eval(_root, _nonce) <= (bigint(1) << 256) / _difficulty; }
stop = false;
BigInteger max = BigInteger.valueOf(2).pow(255);
byte[] target = BigIntegers.asUnsignedByteArray(32,
max.divide(new BigInteger(1, difficulty)));
long newGasLimit = Math.max(125000,
(new BigInteger(1, newBlock.getGasLimit()).longValue() * (1024 - 1) + (newBlock.getGasUsed() * 6 / 5)) / 1024);
newBlock.getHeader().setGasLimit(BigInteger.valueOf(newGasLimit).toByteArray());
byte[] hash = sha3(newBlock.getEncodedWithoutNonce());
byte[] testNonce = new byte[32];
byte[] concat;
while (ByteUtil.increment(testNonce) && !stop) {
if (testNonce[31] == 0 && testNonce[30] == 0) {
System.out.println("mining: " + new BigInteger(1, testNonce));
}
if (testNonce[31] == 0)
sleep();
concat = Arrays.concatenate(hash, testNonce);
byte[] result = sha3(concat);
if (FastByteComparisons.compareTo(result, 0, 32, target, 0, 32) < 0) {
newBlock.setNonce(testNonce);
return true;
}
}
return false; // couldn't find a valid nonce
}
示例7: encodeMachineCodeForVMRun
import org.spongycastle.util.Arrays; //导入方法依赖的package包/类
/**
*
* @param code
* @param init
* @return encoded bytes
*/
public static byte[] encodeMachineCodeForVMRun(byte[] code, byte[] init) {
if (code == null || code.length == 0) throw new RuntimeException("code can't be empty code: " + code);
int numBytes = ByteUtil.numBytes(code.length + "");
byte[] lenBytes = BigIntegers.asUnsignedByteArray(BigInteger.valueOf(code.length));
StringBuffer sb = new StringBuffer();
for (int i = 0; i < lenBytes.length; ++i) {
sb.append(lenBytes[i]).append(" ");
}
// calc real code start position (after the init header)
int pos = 10 + numBytes * 2;
if (init != null) pos+=init.length;
// @push_len @len PUSH1 @src_start PUSH1 0 CODECOPY @push_len @len 0 PUSH1 0 RETURN
String header = String.format("[asm %s %s PUSH1 %d PUSH1 0 CODECOPY %s %s PUSH1 0 RETURN asm]",
"PUSH" + numBytes, sb.toString(), pos , "PUSH" + numBytes, sb.toString());
byte[] headerMachine = compileAssemblyToMachine(header);
byte[] result = init != null ? Arrays.concatenate(init, headerMachine, code) :
Arrays.concatenate(headerMachine, code);
return result;
}
示例8: validateNonce
import org.spongycastle.util.Arrays; //导入方法依赖的package包/类
/**
* Verify that block is valid for its difficulty
*
* @return boolean
*/
public boolean validateNonce() {
BigInteger max = BigInteger.valueOf(2).pow(256);
byte[] target = BigIntegers.asUnsignedByteArray(32,
max.divide(new BigInteger(1, this.getDifficulty())));
byte[] hash = HashUtil.sha3(this.getEncodedWithoutNonce());
byte[] concat = Arrays.concatenate(hash, this.getNonce());
byte[] result = HashUtil.sha3(concat);
return FastByteComparisons.compareTo(result, 0, 32, target, 0, 32) < 0;
}
示例9: mine
import org.spongycastle.util.Arrays; //导入方法依赖的package包/类
/**
* Adds a nonce to given block which complies with the given difficulty
*
* For the PoC series, we use a simplified proof-of-work.
* This is not ASIC resistant and is meant merely as a placeholder.
* It utilizes the bare SHA3 hash function to secure the block chain by requiring
* the SHA3 hash of the concatenation of the nonce and the header’s SHA3 hash to be
* sufficiently low. It is formally defined as PoW:
*
* PoW(H, n) ≡ BE(SHA3(SHA3(RLP(H!n)) ◦ n))
*
* where:
* RLP(H!n) is the RLP encoding of the block header H, not including the
* final nonce component;
* SHA3 is the SHA3 hash function accepting an arbitrary length series of
* bytes and evaluating to a series of 32 bytes (i.e. 256-bit);
* n is the nonce, a series of 32 bytes;
* o is the series concatenation operator;
* BE(X) evaluates to the value equal to X when interpreted as a
* big-endian-encoded integer.
*
* @param newBlock without a valid nonce
* @param difficulty - the mining difficulty
* @return true if valid nonce has been added to the block
*/
public boolean mine(Block newBlock, byte[] difficulty) {
BigInteger max = BigInteger.valueOf(2).pow(256);
byte[] target = BigIntegers.asUnsignedByteArray(32,
max.divide(new BigInteger(1, difficulty)));
byte[] hash = HashUtil.sha3(newBlock.getEncodedWithoutNonce());
byte[] testNonce = new byte[32];
byte[] concat;
while(ByteUtil.increment(testNonce)) {
concat = Arrays.concatenate(hash, testNonce);
byte[] result = HashUtil.sha3(concat);
if(FastByteComparisons.compareTo(result, 0, 32, target, 0, 32) < 0) {
newBlock.setNonce(testNonce);
// System.out.println(Hex.toHexString(newBlock.getEncoded()));
return true;
}
}
return false; // couldn't find a valid nonce
}