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


Java Arrays.copyOfRange方法代码示例

本文整理汇总了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);
}
 
开发者ID:talentchain,项目名称:talchain,代码行数:20,代码来源:EthashAlgo.java

示例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);
}
 
开发者ID:creativechain,项目名称:creacoinj,代码行数:19,代码来源:KeyChainGroupTest.java

示例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);
}
 
开发者ID:creativechain,项目名称:creacoinj,代码行数:27,代码来源:KeyChainGroupTest.java

示例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);
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:19,代码来源:KeyChainGroupTest.java

示例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);
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:27,代码来源:KeyChainGroupTest.java

示例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);
}
 
开发者ID:GemHQ,项目名称:round-java,代码行数:24,代码来源:PassphraseBox.java

示例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);
}
 
开发者ID:creativechain,项目名称:creacoinj,代码行数:30,代码来源:KeyChainGroupTest.java

示例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());
}
 
开发者ID:kit-tm,项目名称:bitnym,代码行数:8,代码来源:BroadcastAnnouncement.java

示例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;
}
 
开发者ID:oversecio,项目名称:oversec_crypto,代码行数:35,代码来源:OversecChacha20Poly1305.java

示例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);
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:30,代码来源:KeyChainGroupTest.java

示例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);
}
 
开发者ID:DigiByte-Team,项目名称:digibytej-alice,代码行数:30,代码来源:KeyChainGroupTest.java

示例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);
    }
 
开发者ID:unfoldingWord-dev,项目名称:uw-android,代码行数:9,代码来源:AudioMarkerParser.java

示例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);
}
 
开发者ID:toshiapp,项目名称:toshi-headless-client,代码行数:5,代码来源:HashUtil.java

示例14: getLast20Bytes

import org.spongycastle.util.Arrays; //导入方法依赖的package包/类
public byte[] getLast20Bytes() {
    return Arrays.copyOfRange(data, 12, data.length);
}
 
开发者ID:talentchain,项目名称:talchain,代码行数:4,代码来源:DataWord.java

示例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);
    }
 
开发者ID:talentchain,项目名称:talchain,代码行数:69,代码来源:EthereumIESEngine.java


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