本文整理汇总了Java中org.spongycastle.util.Arrays.copyOfRange方法的典型用法代码示例。如果您正苦于以下问题:Java Arrays.copyOfRange方法的具体用法?Java Arrays.copyOfRange怎么用?Java Arrays.copyOfRange使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.spongycastle.util.Arrays
的用法示例。
在下文中一共展示了Arrays.copyOfRange方法的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: 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);
}
示例3: 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);
}
示例4: 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);
}
示例5: 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);
}
示例6: 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);
}
示例7: deterministicUpgradeUnencrypted
import org.spongycastle.util.Arrays; //导入方法依赖的package包/类
@Test
public void deterministicUpgradeUnencrypted() throws Exception {
// Check that a group that contains only random keys has its HD chain created using the private key bytes of
// the oldest random key, so upgrading the same wallet twice gives the same outcome.
group = new KeyChainGroup(PARAMS);
group.setLookaheadSize(LOOKAHEAD_SIZE); // Don't want slow tests.
ECKey key1 = new ECKey();
Utils.rollMockClock(86400);
ECKey key2 = new ECKey();
group.importKeys(key2, key1);
List<Protos.Key> protobufs = group.serializeToProtobuf();
group.upgradeToDeterministic(0, null);
assertFalse(group.isDeterministicUpgradeRequired());
DeterministicKey dkey1 = group.freshKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
DeterministicSeed seed1 = group.getActiveKeyChain().getSeed();
assertNotNull(seed1);
group = KeyChainGroup.fromProtobufUnencrypted(PARAMS, protobufs);
group.upgradeToDeterministic(0, null); // Should give same result as last time.
DeterministicKey dkey2 = group.freshKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
DeterministicSeed seed2 = group.getActiveKeyChain().getSeed();
assertEquals(seed1, seed2);
assertEquals(dkey1, dkey2);
// Check we used the right (oldest) key despite backwards import order.
byte[] truncatedBytes = Arrays.copyOfRange(key1.getSecretBytes(), 0, 16);
assertArrayEquals(seed1.getEntropyBytes(), truncatedBytes);
}
示例8: deserialize
import org.spongycastle.util.Arrays; //导入方法依赖的package包/类
public static BroadcastAnnouncement deserialize(byte[] data) {
byte[] onionAdress = Arrays.copyOfRange(data, 7, 23);
byte[] mixValue = Arrays.copyOfRange(data, 23, 27);
byte[] acceptableLoss = Arrays.copyOfRange(data, 27, 31);
return new BroadcastAnnouncement(new String(onionAdress), (new BigInteger(mixValue)).intValue(), (new BigInteger(acceptableLoss)).intValue());
}
示例9: deChacha
import org.spongycastle.util.Arrays; //导入方法依赖的package包/类
public static byte[] deChacha(byte[] ciphertext, byte[] key, byte[] iv) throws MacMismatchException {
boolean encrypt = false;
CipherParameters cp = new KeyParameter(key);
ParametersWithIV params = new ParametersWithIV(cp, iv);
StreamCipher engine = new ChaChaEngine();
//noinspection ConstantConditions
engine.init(encrypt, params);
if (getPlaintextLimit(ciphertext.length) < 0) {
throw new IllegalArgumentException();
}
byte[] macKeyBytes = Arrays.copyOf(key, key.length);
Poly1305KeyGenerator.clamp(macKeyBytes);
KeyParameter macKey = new KeyParameter(macKeyBytes); //initRecord(engine, encrypt, 0, iv);
int plaintextLength = ciphertext.length - 16;
byte[] calculatedMAC = calculateMAC(macKey, ciphertext, 0, plaintextLength);
byte[] receivedMAC = Arrays.copyOfRange(ciphertext, ciphertext.length - 16, ciphertext.length);
if (!Arrays.constantTimeAreEqual(calculatedMAC, receivedMAC)) {
throw new MacMismatchException();
}
byte[] output = new byte[plaintextLength];
engine.processBytes(ciphertext, 0, plaintextLength, output, 0);
KeyUtil.erase(calculatedMAC);
KeyUtil.erase(receivedMAC);
return output;
}
示例10: deterministicUpgradeUnencrypted
import org.spongycastle.util.Arrays; //导入方法依赖的package包/类
@Test
public void deterministicUpgradeUnencrypted() throws Exception {
// Check that a group that contains only random keys has its HD chain created using the private key bytes of
// the oldest random key, so upgrading the same wallet twice gives the same outcome.
group = new KeyChainGroup(params);
group.setLookaheadSize(LOOKAHEAD_SIZE); // Don't want slow tests.
ECKey key1 = new ECKey();
Utils.rollMockClock(86400);
ECKey key2 = new ECKey();
group.importKeys(key2, key1);
List<Protos.Key> protobufs = group.serializeToProtobuf();
group.upgradeToDeterministic(0, null);
assertFalse(group.isDeterministicUpgradeRequired());
DeterministicKey dkey1 = group.freshKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
DeterministicSeed seed1 = group.getActiveKeyChain().getSeed();
assertNotNull(seed1);
group = KeyChainGroup.fromProtobufUnencrypted(params, protobufs, 1);
group.upgradeToDeterministic(0, null); // Should give same result as last time.
DeterministicKey dkey2 = group.freshKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
DeterministicSeed seed2 = group.getActiveKeyChain().getSeed();
assertEquals(seed1, seed2);
assertEquals(dkey1, dkey2);
// Check we used the right (oldest) key despite backwards import order.
byte[] truncatedBytes = Arrays.copyOfRange(key1.getSecretBytes(), 0, 16);
assertArrayEquals(seed1.getEntropyBytes(), truncatedBytes);
}
示例11: deterministicUpgradeUnencrypted
import org.spongycastle.util.Arrays; //导入方法依赖的package包/类
@Test
public void deterministicUpgradeUnencrypted() throws Exception {
// Check that a group that contains only random keys has its HD chain created using the private key bytes of
// the oldest random key, so upgrading the same wallet twice gives the same outcome.
group = new KeyChainGroup(params);
group.setLookaheadSize(LOOKAHEAD_SIZE); // Don't want slow tests.
ECKey key1 = new ECKey();
Utils.rollMockClock(86400);
ECKey key2 = new ECKey();
group.importKeys(key2, key1);
List<Protos.Key> protobufs = group.serializeToProtobuf();
group.upgradeToDeterministic(0, null);
assertFalse(group.isDeterministicUpgradeRequired());
DeterministicKey dkey1 = group.freshKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
DeterministicSeed seed1 = group.getActiveKeyChain().getSeed();
assertNotNull(seed1);
group = KeyChainGroup.fromProtobufUnencrypted(params, protobufs);
group.upgradeToDeterministic(0, null); // Should give same result as last time.
DeterministicKey dkey2 = group.freshKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
DeterministicSeed seed2 = group.getActiveKeyChain().getSeed();
assertEquals(seed1, seed2);
assertEquals(dkey1, dkey2);
// Check we used the right (oldest) key despite backwards import order.
byte[] truncatedBytes = Arrays.copyOfRange(key1.getSecretBytes(), 0, 16);
assertArrayEquals(seed1.getEntropyBytes(), truncatedBytes);
}
示例12: getHeaderBytes
import org.spongycastle.util.Arrays; //导入方法依赖的package包/类
private static byte[] getHeaderBytes(File file){
byte[] audioBytes = FileUtil.getBytesFromFile(file);
if(audioBytes == null){
return null;
}
return Arrays.copyOfRange(audioBytes, 0, 500 * 1000);
}
示例13: sha3omit12
import org.spongycastle.util.Arrays; //导入方法依赖的package包/类
public static byte[] sha3omit12(byte[] input) {
byte[] hash = sha3(input);
return Arrays.copyOfRange(hash, 12, hash.length);
}
示例14: getLast20Bytes
import org.spongycastle.util.Arrays; //导入方法依赖的package包/类
public byte[] getLast20Bytes() {
return Arrays.copyOfRange(data, 12, data.length);
}
示例15: processBlock
import org.spongycastle.util.Arrays; //导入方法依赖的package包/类
public byte[] processBlock(
byte[] in,
int inOff,
int inLen,
byte[] macData)
throws InvalidCipherTextException
{
if (forEncryption)
{
if (keyPairGenerator != null)
{
EphemeralKeyPair ephKeyPair = keyPairGenerator.generate();
this.privParam = ephKeyPair.getKeyPair().getPrivate();
this.V = ephKeyPair.getEncodedPublicKey();
}
}
else
{
if (keyParser != null)
{
ByteArrayInputStream bIn = new ByteArrayInputStream(in, inOff, inLen);
try
{
this.pubParam = keyParser.readKey(bIn);
}
catch (IOException e)
{
throw new InvalidCipherTextException("unable to recover ephemeral public key: " + e.getMessage(), e);
}
int encLength = (inLen - bIn.available());
this.V = Arrays.copyOfRange(in, inOff, inOff + encLength);
}
}
// Compute the common value and convert to byte array.
agree.init(privParam);
BigInteger z = agree.calculateAgreement(pubParam);
byte[] Z = BigIntegers.asUnsignedByteArray(agree.getFieldSize(), z);
// Create input to KDF.
byte[] VZ;
// if (V.length != 0)
// {
// VZ = new byte[V.length + Z.length];
// System.arraycopy(V, 0, VZ, 0, V.length);
// System.arraycopy(Z, 0, VZ, V.length, Z.length);
// }
// else
{
VZ = Z;
}
// Initialise the KDF.
DerivationParameters kdfParam;
if (kdf instanceof MGF1BytesGeneratorExt) {
kdfParam = new MGFParameters(VZ);
} else {
kdfParam = new KDFParameters(VZ, param.getDerivationV());
}
kdf.init(kdfParam);
return forEncryption
? encryptBlock(in, inOff, inLen, macData)
: decryptBlock(in, inOff, inLen, macData);
}