本文整理汇总了Java中org.spongycastle.util.Arrays类的典型用法代码示例。如果您正苦于以下问题:Java Arrays类的具体用法?Java Arrays怎么用?Java Arrays使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Arrays类属于org.spongycastle.util包,在下文中一共展示了Arrays类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: calcDatasetItem
import org.spongycastle.util.Arrays; //导入依赖的package包/类
public final int[] calcDatasetItem(final int[] cache, final int i) {
final int r = params.getHASH_BYTES() / params.getWORD_BYTES();
final int n = cache.length / r;
int[] mix = Arrays.copyOfRange(cache, i % n * r, (i % n + 1) * r);
mix[0] = i ^ mix[0];
mix = sha512(mix, false);
final int dsParents = (int) params.getDATASET_PARENTS();
final int mixLen = mix.length;
for (int j = 0; j < dsParents; j++) {
int cacheIdx = fnv(i ^ j, mix[j % r]);
cacheIdx = remainderUnsigned(cacheIdx, n);
int off = cacheIdx * r;
for (int k = 0; k < mixLen; k++) {
mix[k] = fnv(mix[k], cache[off + k]);
}
}
return sha512(mix, false);
}
示例2: testAddressStringToBytes
import org.spongycastle.util.Arrays; //导入依赖的package包/类
@Test
public void testAddressStringToBytes() {
// valid address
String HexStr = "6c386a4b26f73c802f34673f7248bb118f97424a";
byte[] expected = Hex.decode(HexStr);
byte[] result = Utils.addressStringToBytes(HexStr);
assertEquals(Arrays.areEqual(expected, result), true);
// invalid address, we removed the last char so it cannot decode
HexStr = "6c386a4b26f73c802f34673f7248bb118f97424";
expected = null;
result = Utils.addressStringToBytes(HexStr);
assertEquals(expected, result);
// invalid address, longer than 20 bytes
HexStr = new String(Hex.encode("I am longer than 20 bytes, i promise".getBytes()));
expected = null;
result = Utils.addressStringToBytes(HexStr);
assertEquals(expected, result);
// invalid address, shorter than 20 bytes
HexStr = new String(Hex.encode("I am short".getBytes()));
expected = null;
result = Utils.addressStringToBytes(HexStr);
assertEquals(expected, result);
}
示例3: update
import org.spongycastle.util.Arrays; //导入依赖的package包/类
/**
* Update the message digest with a single byte.
*
* @param b the input byte to be entered.
*/
public void update(byte b) {
int remainingLength; // left bytes of buffer
// process the buffer if full else add to buffer:
remainingLength = BLOCK_LENGTH_BYTES - bufferPos;
if (remainingLength == 0) { // full buffer
t0 += BLOCK_LENGTH_BYTES;
if (t0 == 0) { // if message > 2^32
t1++;
}
compress(buffer, 0);
Arrays.fill(buffer, (byte)0);// clear buffer
buffer[0] = b;
bufferPos = 1;
} else {
buffer[bufferPos] = b;
bufferPos++;
}
}
示例4: 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);
}
示例5: 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;
}
示例6: deterministicUpgradeRotating
import org.spongycastle.util.Arrays; //导入依赖的package包/类
@Test
public void deterministicUpgradeRotating() throws Exception {
group = new KeyChainGroup(PARAMS);
group.setLookaheadSize(LOOKAHEAD_SIZE); // Don't want slow tests.
long now = Utils.currentTimeSeconds();
ECKey key1 = new ECKey();
Utils.rollMockClock(86400);
ECKey key2 = new ECKey();
Utils.rollMockClock(86400);
ECKey key3 = new ECKey();
group.importKeys(key2, key1, key3);
group.upgradeToDeterministic(now + 10, null);
DeterministicSeed seed = group.getActiveKeyChain().getSeed();
assertNotNull(seed);
// Check we used the right key: oldest non rotating.
byte[] truncatedBytes = Arrays.copyOfRange(key2.getSecretBytes(), 0, 16);
assertArrayEquals(seed.getEntropyBytes(), truncatedBytes);
}
示例7: deterministicUpgradeEncrypted
import org.spongycastle.util.Arrays; //导入依赖的package包/类
@Test
public void deterministicUpgradeEncrypted() throws Exception {
group = new KeyChainGroup(PARAMS);
final ECKey key = new ECKey();
group.importKeys(key);
final KeyCrypterScrypt crypter = new KeyCrypterScrypt();
final KeyParameter aesKey = crypter.deriveKey("abc");
assertTrue(group.isDeterministicUpgradeRequired());
group.encrypt(crypter, aesKey);
assertTrue(group.isDeterministicUpgradeRequired());
try {
group.upgradeToDeterministic(0, null);
fail();
} catch (DeterministicUpgradeRequiresPassword e) {
// Expected.
}
group.upgradeToDeterministic(0, aesKey);
assertFalse(group.isDeterministicUpgradeRequired());
final DeterministicSeed deterministicSeed = group.getActiveKeyChain().getSeed();
assertNotNull(deterministicSeed);
assertTrue(deterministicSeed.isEncrypted());
byte[] entropy = checkNotNull(group.getActiveKeyChain().toDecrypted(aesKey).getSeed()).getEntropyBytes();
// Check we used the right key: oldest non rotating.
byte[] truncatedBytes = Arrays.copyOfRange(key.getSecretBytes(), 0, 16);
assertArrayEquals(entropy, truncatedBytes);
}
示例8: deterministicUpgradeRotating
import org.spongycastle.util.Arrays; //导入依赖的package包/类
@Test
public void deterministicUpgradeRotating() throws Exception {
group = new KeyChainGroup(params);
group.setLookaheadSize(LOOKAHEAD_SIZE); // Don't want slow tests.
long now = Utils.currentTimeSeconds();
ECKey key1 = new ECKey();
Utils.rollMockClock(86400);
ECKey key2 = new ECKey();
Utils.rollMockClock(86400);
ECKey key3 = new ECKey();
group.importKeys(key2, key1, key3);
group.upgradeToDeterministic(now + 10, null);
DeterministicSeed seed = group.getActiveKeyChain().getSeed();
assertNotNull(seed);
// Check we used the right key: oldest non rotating.
byte[] truncatedBytes = Arrays.copyOfRange(key2.getSecretBytes(), 0, 16);
assertArrayEquals(seed.getEntropyBytes(), truncatedBytes);
}
示例9: deterministicUpgradeEncrypted
import org.spongycastle.util.Arrays; //导入依赖的package包/类
@Test
public void deterministicUpgradeEncrypted() throws Exception {
group = new KeyChainGroup(params);
final ECKey key = new ECKey();
group.importKeys(key);
final KeyCrypterScrypt crypter = new KeyCrypterScrypt();
final KeyParameter aesKey = crypter.deriveKey("abc");
assertTrue(group.isDeterministicUpgradeRequired());
group.encrypt(crypter, aesKey);
assertTrue(group.isDeterministicUpgradeRequired());
try {
group.upgradeToDeterministic(0, null);
fail();
} catch (DeterministicUpgradeRequiresPassword e) {
// Expected.
}
group.upgradeToDeterministic(0, aesKey);
assertFalse(group.isDeterministicUpgradeRequired());
final DeterministicSeed deterministicSeed = group.getActiveKeyChain().getSeed();
assertNotNull(deterministicSeed);
assertTrue(deterministicSeed.isEncrypted());
byte[] entropy = checkNotNull(group.getActiveKeyChain().toDecrypted(aesKey).getSeed()).getEntropyBytes();
// Check we used the right key: oldest non rotating.
byte[] truncatedBytes = Arrays.copyOfRange(key.getSecretBytes(), 0, 16);
assertArrayEquals(entropy, truncatedBytes);
}
示例10: updateObjectChunk
import org.spongycastle.util.Arrays; //导入依赖的package包/类
private void updateObjectChunk(String objectId, int offset, byte[] data,
int dataOffset, int dataLen) throws IOException {
connect();
int lc = dataLen + 9;
String cmd = String.format(
"B0 54 00 00 %02x %s %s %02x %s",
lc,
objectId,
Hex.toHex(offset),
dataLen,
Hex.toHex(Arrays.copyOfRange(data, dataOffset, dataOffset
+ dataLen)));
ResponseApdu rapdu = transceive(cmd);
if (DEBUG) {
Log.d(TAG, "UPDATE OBJECT: " + rapdu.toString());
}
checkSw(rapdu);
}
示例11: payloadWithChecksumTest
import org.spongycastle.util.Arrays; //导入依赖的package包/类
@Test
public void payloadWithChecksumTest() {
String pl = "I am the payload";
byte[] plBytes = pl.getBytes();
String aes = "d8d2b7a00a615ead144bcb02abe325fb955415484003eee969339d7d32f8ca3a";
SecretKey key = new SecretKeySpec(Hex.decode(aes), "AES");
assertTrue(key != null);
String expectedStr = "4920616d20746865207061796c6f61642c1624c2fdb59ff7b8bff02e84a11fb9ee82037383b2ca942185d5665d769a1e";
byte[] expected = Hex.decode(expectedStr);
byte[] result = CryptoUtils.payloadWithChecksum(plBytes, key);
assertTrue(result != null);
assertTrue(Arrays.areEqual(result, expected));
}
示例12: testAddressStringToBytes
import org.spongycastle.util.Arrays; //导入依赖的package包/类
@Test
public void testAddressStringToBytes() {
// valid address
String HexStr = "6c386a4b26f73c802f34673f7248bb118f97424a";
byte[] expected = Hex.decode(HexStr);
byte[] result = Utils.addressStringToBytes(HexStr);
assertEquals(Arrays.areEqual(expected, result), true);
// invalid address, we removed the last char so it cannot decode
HexStr = "6c386a4b26f73c802f34673f7248bb118f97424";
expected = null;
result = Utils.addressStringToBytes(HexStr);
assertEquals(expected, result);
// invalid address, longer than 20 bytes
HexStr = new String(Hex.encode("I am longer than 20 bytes, i promise".getBytes()));
expected = null;
result = Utils.addressStringToBytes(HexStr);
assertEquals(expected, result);
// invalid address, shorter than 20 bytes
HexStr = new String(Hex.encode("I am short".getBytes()));
expected = null;
result = Utils.addressStringToBytes(HexStr);
assertEquals(expected, result);
}
示例13: getValueAt
import org.spongycastle.util.Arrays; //导入依赖的package包/类
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
if(columnIndex == 0) {
return Hex.toHexString(data.get(rowIndex).address);
}
else if(columnIndex == 1 ){
if(data.get(rowIndex).accountState != null) {
return Denomination.toFriendlyString(data.get(rowIndex).accountState.getBalance());
}
return "---";
}
else {
if(data.get(rowIndex).accountState != null) {
if(!Arrays.areEqual(data.get(rowIndex).accountState.getCodeHash(), HashUtil.EMPTY_DATA_HASH))
return "Yes";
}
return "No";
}
}
示例14: decryptAes
import org.spongycastle.util.Arrays; //导入依赖的package包/类
public String decryptAes(String iv, String ciphertext) throws
InvalidAlgorithmParameterException, InvalidKeyException, BadPaddingException,
IllegalBlockSizeException, UnsupportedEncodingException, InvalidCipherTextException,
NoSuchAlgorithmException {
this.iv = Hex.decode(iv);
byte[] ctext = Hex.decode(ciphertext);
// This "ciphertext" that we import is constructed from actual_ciphertext + hmacsha1(iv + actual_ciphertext)
byte[] ctextb = Arrays.copyOfRange(ctext, 0, ctext.length - 32);
byte[] mac = Arrays.copyOfRange(ctext, ctext.length - 32, ctext.length);
// Recreate the hmac and verify it matches.
Mac hmac = Mac.getInstance("HmacSHA256");
hmac.init(this.hmacSecretKey);
if (!Arrays.areEqual(mac, hmac.doFinal(Arrays.concatenate(this.iv, ctextb)))) {
throw new RuntimeException("Invalid authentication code: ciphertext may have been tampered with.");
}
// Decrypt the actual_ciphertext.
CipherParameters ivAndKey = new ParametersWithIV(new KeyParameter(aesKey), this.iv);
decryptCipher.init(false, ivAndKey);
return new String(cipherData(decryptCipher, ctextb), UTF_8);
}
示例15: 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;
}