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


Java Arrays.fill方法代码示例

本文整理汇总了Java中org.bouncycastle.util.Arrays.fill方法的典型用法代码示例。如果您正苦于以下问题:Java Arrays.fill方法的具体用法?Java Arrays.fill怎么用?Java Arrays.fill使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bouncycastle.util.Arrays的用法示例。


在下文中一共展示了Arrays.fill方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: encrypt

import org.bouncycastle.util.Arrays; //导入方法依赖的package包/类
/**
 * Encrypts a BigInteger aka Plaintext with the public key.
 * 
 * @param plain
 *            The BigInteger to encrypt
 * @return The byte[] representation of the encrypted BigInteger (i.e.
 *         crypted.toByteArray())
 */
public byte[] encrypt(BigInteger plain)
{
    // Always return modulus size values 0-padded at the beginning
    // 0-padding at the beginning is correctly parsed by BigInteger :)
    byte[] output = key.getModulus().toByteArray();
    Arrays.fill(output, (byte)0);
    byte[] tmp = key.getG().modPow(plain, key.getModulus()).toByteArray();
    System
            .arraycopy(tmp, 0, output, output.length - tmp.length,
                    tmp.length);
    if (debug)
    {
        System.out
                .println("Encrypted value is:  " + new BigInteger(output));
    }
    return output;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:26,代码来源:NaccacheSternEngine.java

示例2: establishMasterSecret

import org.bouncycastle.util.Arrays; //导入方法依赖的package包/类
protected static void establishMasterSecret(TlsContext context, TlsKeyExchange keyExchange)
    throws IOException
{

    byte[] pre_master_secret = keyExchange.generatePremasterSecret();

    try
    {
        context.getSecurityParameters().masterSecret = TlsUtils.calculateMasterSecret(context, pre_master_secret);
    }
    finally
    {
        // TODO Is there a way to ensure the data is really overwritten?
        /*
         * RFC 2246 8.1. The pre_master_secret should be deleted from memory once the
         * master_secret has been computed.
         */
        if (pre_master_secret != null)
        {
            Arrays.fill(pre_master_secret, (byte)0);
        }
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:24,代码来源:TlsProtocol.java

示例3: initSponge

import org.bouncycastle.util.Arrays; //导入方法依赖的package包/类
private void initSponge(int rate, int capacity)
{
    if (rate + capacity != 1600)
    {
        throw new IllegalStateException("rate + capacity != 1600");
    }
    if ((rate <= 0) || (rate >= 1600) || ((rate % 64) != 0))
    {
        throw new IllegalStateException("invalid rate value");
    }

    this.rate = rate;
    // this is never read, need to check to see why we want to save it
    //  this.capacity = capacity;
    this.fixedOutputLength = 0;
    Arrays.fill(this.state, (byte)0);
    Arrays.fill(this.dataQueue, (byte)0);
    this.bitsInQueue = 0;
    this.squeezing = false;
    this.bitsAvailableForSqueezing = 0;
    this.fixedOutputLength = capacity / 2;
    this.chunk = new byte[rate / 8];
    this.oneByte = new byte[1];
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:25,代码来源:SHA3Digest.java

示例4: reset

import org.bouncycastle.util.Arrays; //导入方法依赖的package包/类
/**
 * reset the chaining vector back to the IV and reset the underlying
 * cipher.
 */
public void reset()
{
    System.arraycopy(IV, 0, cbcV, 0, IV.length);
    Arrays.fill(cbcNextV, (byte)0);

    cipher.reset();
}
 
开发者ID:PhilippC,项目名称:keepass2android,代码行数:12,代码来源:CBCBlockCipher.java

示例5: genConst

import org.bouncycastle.util.Arrays; //导入方法依赖的package包/类
private static byte[][] genConst()
{
    int n = 10;
    byte[][] arr = new byte[n][];
    for (int i = 0; i < n; i++)
    {
        byte[] b = new byte[i + 1];
        Arrays.fill(b, (byte)('A' + i));
        arr[i] = b;
    }
    return arr;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:13,代码来源:TlsUtils.java

示例6: calculateMacTag

import org.bouncycastle.util.Arrays; //导入方法依赖的package包/类
/**
 * Calculates the MacTag (to be used for key confirmation), as defined by
 * <a href="http://csrc.nist.gov/publications/nistpubs/800-56A/SP800-56A_Revision1_Mar08-2007.pdf">NIST SP 800-56A Revision 1</a>,
 * Section 8.2 Unilateral Key Confirmation for Key Agreement Schemes.
 * <p/>
 * <p/>
 * <pre>
 * MacTag = HMAC(MacKey, MacLen, MacData)
 *
 * MacKey = H(K || "JPAKE_KC")
 *
 * MacData = "KC_1_U" || participantId || partnerParticipantId || gx1 || gx2 || gx3 || gx4
 *
 * Note that both participants use "KC_1_U" because the sender of the round 3 message
 * is always the initiator for key confirmation.
 *
 * HMAC = {@link HMac} used with the given {@link Digest}
 * H = The given {@link Digest}</li>
 * MacLen = length of MacTag
 * </pre>
 * <p/>
 */
public static BigInteger calculateMacTag(
    String participantId,
    String partnerParticipantId,
    BigInteger gx1,
    BigInteger gx2,
    BigInteger gx3,
    BigInteger gx4,
    BigInteger keyingMaterial,
    Digest digest)
{
    byte[] macKey = calculateMacKey(
        keyingMaterial,
        digest);

    HMac mac = new HMac(digest);
    byte[] macOutput = new byte[mac.getMacSize()];
    mac.init(new KeyParameter(macKey));
    
    /*
     * MacData = "KC_1_U" || participantId_Alice || participantId_Bob || gx1 || gx2 || gx3 || gx4.
     */
    updateMac(mac, "KC_1_U");
    updateMac(mac, participantId);
    updateMac(mac, partnerParticipantId);
    updateMac(mac, gx1);
    updateMac(mac, gx2);
    updateMac(mac, gx3);
    updateMac(mac, gx4);

    mac.doFinal(macOutput, 0);

    Arrays.fill(macKey, (byte)0);

    return new BigInteger(macOutput);

}
 
开发者ID:Appdome,项目名称:ipack,代码行数:59,代码来源:JPAKEUtil.java

示例7: updateDigestIncludingSize

import org.bouncycastle.util.Arrays; //导入方法依赖的package包/类
private static void updateDigestIncludingSize(Digest digest, BigInteger bigInteger)
{
    byte[] byteArray = BigIntegers.asUnsignedByteArray(bigInteger);
    digest.update(intToByteArray(byteArray.length), 0, 4);
    digest.update(byteArray, 0, byteArray.length);
    Arrays.fill(byteArray, (byte)0);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:8,代码来源:JPAKEUtil.java

示例8: reset

import org.bouncycastle.util.Arrays; //导入方法依赖的package包/类
private void reset(
    boolean clearMac)
{
    cipher.reset();

    S = new byte[BLOCK_SIZE];
    S_at = new byte[BLOCK_SIZE];
    S_atPre = new byte[BLOCK_SIZE];
    atBlock = new byte[BLOCK_SIZE];
    atBlockPos = 0;
    atLength = 0;
    atLengthPre = 0;
    counter = Arrays.clone(J0);
    bufOff = 0;
    totalLength = 0;

    if (bufBlock != null)
    {
        Arrays.fill(bufBlock, (byte)0);
    }

    if (clearMac)
    {
        macBlock = null;
    }

    if (initialAssociatedText != null)
    {
        processAADBytes(initialAssociatedText, 0, initialAssociatedText.length);
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:32,代码来源:GCMBlockCipher.java

示例9: reset

import org.bouncycastle.util.Arrays; //导入方法依赖的package包/类
public void reset()
{

    v0 = k0 ^ 0x736f6d6570736575L;
    v1 = k1 ^ 0x646f72616e646f6dL;
    v2 = k0 ^ 0x6c7967656e657261L;
    v3 = k1 ^ 0x7465646279746573L;

    Arrays.fill(buf, (byte)0);
    bufPos = 0;
    wordCount = 0;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:13,代码来源:SipHash.java

示例10: Clear

import org.bouncycastle.util.Arrays; //导入方法依赖的package包/类
private static void Clear(int[] array)
{
    if (array != null)
    {
        Arrays.fill(array, 0);
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:8,代码来源:SCrypt.java

示例11: processFilledBuffer

import org.bouncycastle.util.Arrays; //导入方法依赖的package包/类
private void processFilledBuffer(byte[] in, int inOff)
{
    // copies into the block...
    for (int i = 0; i < _state.length; i++)
    {
        _block[i] = bytesToLongFromBuffer(_buffer, i * 8);
    }
    processBlock();
    _bufferPos = 0;
    Arrays.fill(_buffer, (byte)0);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:12,代码来源:WhirlpoolDigest.java

示例12: HMacSP800DRBG

import org.bouncycastle.util.Arrays; //导入方法依赖的package包/类
/**
 * Construct a SP800-90A Hash DRBG.
 * <p>
 * Minimum entropy requirement is the security strength requested.
 * </p>
 * @param hMac Hash MAC to base the DRBG on.
 * @param securityStrength security strength required (in bits)
 * @param entropySource source of entropy to use for seeding/reseeding.
 * @param personalizationString personalization string to distinguish this DRBG (may be null).
 * @param nonce nonce to further distinguish this DRBG (may be null).
 */
public HMacSP800DRBG(Mac hMac, int securityStrength, EntropySource entropySource, byte[] personalizationString, byte[] nonce)
{
    if (securityStrength > Utils.getMaxSecurityStrength(hMac))
    {
        throw new IllegalArgumentException("Requested security strength is not supported by the derivation function");
    }

    if (entropySource.entropySize() < securityStrength)
    {
        throw new IllegalArgumentException("Not enough entropy for security strength required");
    }

    _entropySource = entropySource;
    _hMac = hMac;

    byte[] entropy = entropySource.getEntropy();
    byte[] seedMaterial = Arrays.concatenate(entropy, nonce, personalizationString);

    _K = new byte[hMac.getMacSize()];
    _V = new byte[_K.length];
    Arrays.fill(_V, (byte)1);

    hmac_DRBG_Update(seedMaterial);

    _reseedCounter = 1;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:38,代码来源:HMacSP800DRBG.java

示例13: clear

import org.bouncycastle.util.Arrays; //导入方法依赖的package包/类
protected void clear(byte[] bs)
{
    if (bs != null)
    {
        Arrays.fill(bs, (byte)0);
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:8,代码来源:OCBBlockCipher.java

示例14: addCryptedBlocks

import org.bouncycastle.util.Arrays; //导入方法依赖的package包/类
/**
 * Adds the contents of two encrypted blocks mod sigma
 * 
 * @param block1
 *            the first encrypted block
 * @param block2
 *            the second encrypted block
 * @return encrypt((block1 + block2) mod sigma)
 * @throws InvalidCipherTextException
 */
public byte[] addCryptedBlocks(byte[] block1, byte[] block2)
        throws InvalidCipherTextException
{
    // check for correct blocksize
    if (forEncryption)
    {
        if ((block1.length > getOutputBlockSize())
                || (block2.length > getOutputBlockSize()))
        {
            throw new InvalidCipherTextException(
                    "BlockLength too large for simple addition.\n");
        }
    }
    else
    {
        if ((block1.length > getInputBlockSize())
                || (block2.length > getInputBlockSize()))
        {
            throw new InvalidCipherTextException(
                    "BlockLength too large for simple addition.\n");
        }
    }

    // calculate resulting block
    BigInteger m1Crypt = new BigInteger(1, block1);
    BigInteger m2Crypt = new BigInteger(1, block2);
    BigInteger m1m2Crypt = m1Crypt.multiply(m2Crypt);
    m1m2Crypt = m1m2Crypt.mod(key.getModulus());
    if (debug)
    {
        System.out.println("c(m1) as BigInteger:....... " + m1Crypt);
        System.out.println("c(m2) as BigInteger:....... " + m2Crypt);
        System.out.println("c(m1)*c(m2)%n = c(m1+m2)%n: " + m1m2Crypt);
    }

    byte[] output = key.getModulus().toByteArray();
    Arrays.fill(output, (byte)0);
    System.arraycopy(m1m2Crypt.toByteArray(), 0, output, output.length
            - m1m2Crypt.toByteArray().length,
            m1m2Crypt.toByteArray().length);

    return output;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:54,代码来源:NaccacheSternEngine.java

示例15: calculateKeyingMaterial

import org.bouncycastle.util.Arrays; //导入方法依赖的package包/类
/**
 * Calculates and returns the key material.
 * A session key must be derived from this key material using a secure key derivation function (KDF).
 * The KDF used to derive the key is handled externally (i.e. not by {@link JPAKEParticipant}).
 * <p/>
 * <p/>
 * The keying material will be identical for each participant if and only if
 * each participant's password is the same.  i.e. If the participants do not
 * share the same password, then each participant will derive a different key.
 * Therefore, if you immediately start using a key derived from
 * the keying material, then you must handle detection of incorrect keys.
 * If you want to handle this detection explicitly, you can optionally perform
 * rounds 3 and 4.  See {@link JPAKEParticipant} for details on how to execute
 * rounds 3 and 4.
 * <p/>
 * <p/>
 * The keying material will be in the range <tt>[0, p-1]</tt>.
 * <p/>
 * <p/>
 * {@link #validateRound2PayloadReceived(JPAKERound2Payload)} must be called prior to this method.
 * <p/>
 * <p/>
 * As a side effect, the internal {@link #password} array is cleared, since it is no longer needed.
 * <p/>
 * <p/>
 * After execution, the {@link #getState() state} will be  {@link #STATE_KEY_CALCULATED}.
 *
 * @throws IllegalStateException if called prior to {@link #validateRound2PayloadReceived(JPAKERound2Payload)},
 * or if called multiple times.
 */
public BigInteger calculateKeyingMaterial()
{
    if (this.state >= STATE_KEY_CALCULATED)
    {
        throw new IllegalStateException("Key already calculated for " + participantId);
    }
    if (this.state < STATE_ROUND_2_VALIDATED)
    {
        throw new IllegalStateException("Round2 payload must be validated prior to creating key for " + participantId);
    }
    BigInteger s = JPAKEUtil.calculateS(password);
    
    /*
     * Clear the password array from memory, since we don't need it anymore.
     * 
     * Also set the field to null as a flag to indicate that the key has already been calculated.
     */
    Arrays.fill(password, (char)0);
    this.password = null;

    BigInteger keyingMaterial = JPAKEUtil.calculateKeyingMaterial(p, q, gx4, x2, s, b);
    
    /*
     * Clear the ephemeral private key fields as well.
     * Note that we're relying on the garbage collector to do its job to clean these up.
     * The old objects will hang around in memory until the garbage collector destroys them.
     * 
     * If the ephemeral private keys x1 and x2 are leaked,
     * the attacker might be able to brute-force the password.
     */
    this.x1 = null;
    this.x2 = null;
    this.b = null;
    
    /*
     * Do not clear gx* yet, since those are needed by round 3.
     */

    this.state = STATE_KEY_CALCULATED;

    return keyingMaterial;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:73,代码来源:JPAKEParticipant.java


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