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


Java DigestInputStream.on方法代码示例

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


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

示例1: processDigest

import java.security.DigestInputStream; //导入方法依赖的package包/类
/**
 * This method allows to compute the digest of the TBSCertList
 * 
 * @param s
 *            an initialized DigestInputStream
 * @throws IOException
 */
public void processDigest(DigestInputStream s) throws IOException {

	// We don't digest the beginning (not part of TBS)
	s.on(false);

	// Skip CertificateList Sequence info
	consumeTagIntro(s);

	// Start to digest TBS
	s.on(true);

	// Strip the tag and length of the TBSCertList sequence
	int tag = DERUtil.readTag(s);
	DERUtil.readTagNumber(s, tag);
	int tbsLength = DERUtil.readLength(s);

	// Read TBSCertList Content
	readNbBytes(s, tbsLength);

	// End digest TBS
	s.on(false);
}
 
开发者ID:esig,项目名称:dss,代码行数:30,代码来源:CRLParser.java

示例2: testRead06

import java.security.DigestInputStream; //导入方法依赖的package包/类
/**
 * Test #6 for <code>read()</code> method<br>
 * Test #2 for <code>on(boolean)</code> method<br>
 *
 * Assertion: broken <code>DigestInputStream</code>instance:
 * associated <code>MessageDigest</code> not set.
 * <code>read()</code> must work when digest
 * functionality is off
 */
@TestTargetNew(
    level = TestLevel.PARTIAL_COMPLETE,
    notes = "",
    method = "read",
    args = {}
)
public final void testRead06()
    throws IOException {
    InputStream is = new ByteArrayInputStream(myMessage);
    // construct object without digest
    DigestInputStream dis = new DigestInputStream(is, null);
    // set digest functionality to off
    dis.on(false);
    // the following must pass without any exception
    for (int i=0; i<MY_MESSAGE_LEN; i++) {
        assertTrue((byte)dis.read() == myMessage[i]);
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:28,代码来源:DigestInputStreamTest.java

示例3: testRead03

import java.security.DigestInputStream; //导入方法依赖的package包/类
/**
 * Test #3 for <code>read()</code> method<br>
 * Test #1 for <code>on(boolean)</code> method<br>
 * 
 * Assertion: <code>read()</code> must not update digest if it is off<br>
 * Assertion: <code>on(boolean)</code> turns digest functionality on
 * (if <code>true</code> passed as a parameter) or off (if <code>false</code>
 *  passed)
 */
public final void testRead03()
    throws IOException {
    for (int ii=0; ii<algorithmName.length; ii++) {
        try {
            MessageDigest md = MessageDigest.getInstance(algorithmName[ii]);
            InputStream is = new ByteArrayInputStream(myMessage);
            DigestInputStream dis = new DigestInputStream(is, md);
            
            // turn digest off
            dis.on(false);
            
            for (int i=0; i<MY_MESSAGE_LEN; i++) {
                dis.read();
            }
            
            // check that digest value has not been updated by read()
            assertTrue(Arrays.equals(dis.getMessageDigest().digest(),
                    MDGoldenData.getDigest(algorithmName[ii]+"_NU")));
            return;
        } catch (NoSuchAlgorithmException e) {
            // allowed failure
        }
    }
    fail(getName() + ": no MessageDigest algorithms available - test not performed");
}
 
开发者ID:shannah,项目名称:cn1,代码行数:35,代码来源:DigestInputStreamTest.java

示例4: readBinary

import java.security.DigestInputStream; //导入方法依赖的package包/类
private Sha256Hash readBinary(InputStream inputStream) throws IOException {
    DataInputStream dis = null;
    try {
        MessageDigest digest = Sha256Hash.newDigest();
        DigestInputStream digestInputStream = new DigestInputStream(inputStream, digest);
        dis = new DataInputStream(digestInputStream);
        digestInputStream.on(false);
        byte[] header = new byte[BINARY_MAGIC.length()];
        dis.readFully(header);
        if (!Arrays.equals(header, BINARY_MAGIC.getBytes("US-ASCII")))
            throw new IOException("Header bytes did not match expected version");
        int numSignatures = checkPositionIndex(dis.readInt(), MAX_SIGNATURES, "Num signatures out of range");
        for (int i = 0; i < numSignatures; i++) {
            byte[] sig = new byte[65];
            dis.readFully(sig);
            // TODO: Do something with the signature here.
        }
        digestInputStream.on(true);
        int numCheckpoints = dis.readInt();
        checkState(numCheckpoints > 0);
        final int size = StoredBlock.COMPACT_SERIALIZED_SIZE;
        ByteBuffer buffer = ByteBuffer.allocate(size);
        for (int i = 0; i < numCheckpoints; i++) {
            if (dis.read(buffer.array(), 0, size) < size)
                throw new IOException("Incomplete read whilst loading checkpoints.");
            StoredBlock block = StoredBlock.deserializeCompact(params, buffer);
            buffer.position(0);
            checkpoints.put(block.getHeader().getTimeSeconds(), block);
        }
        Sha256Hash dataHash = Sha256Hash.wrap(digest.digest());
        log.info("Read {} checkpoints, hash is {}", checkpoints.size(), dataHash);
        return dataHash;
    } catch (ProtocolException e) {
        throw new IOException(e);
    } finally {
        if (dis != null) dis.close();
        inputStream.close();
    }
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:40,代码来源:CheckpointManager.java

示例5: testRead03

import java.security.DigestInputStream; //导入方法依赖的package包/类
/**
 * Test #3 for <code>read()</code> method<br>
 * Test #1 for <code>on(boolean)</code> method<br>
 *
 * Assertion: <code>read()</code> must not update digest if it is off<br>
 * Assertion: <code>on(boolean)</code> turns digest functionality on
 * (if <code>true</code> passed as a parameter) or off (if <code>false</code>
 *  passed)
 */
@TestTargetNew(
    level = TestLevel.PARTIAL_COMPLETE,
    notes = "",
    method = "read",
    args = {}
)
public final void testRead03()
    throws IOException {
    for (int ii=0; ii<algorithmName.length; ii++) {
        try {
            MessageDigest md = MessageDigest.getInstance(algorithmName[ii]);
            InputStream is = new ByteArrayInputStream(myMessage);
            DigestInputStream dis = new DigestInputStream(is, md);

            // turn digest off
            dis.on(false);

            for (int i=0; i<MY_MESSAGE_LEN; i++) {
                dis.read();
            }

            // check that digest value has not been updated by read()
            assertTrue(Arrays.equals(dis.getMessageDigest().digest(),
                    MDGoldenData.getDigest(algorithmName[ii]+"_NU")));
            return;
        } catch (NoSuchAlgorithmException e) {
            // allowed failure
        }
    }
    fail(getName() + ": no MessageDigest algorithms available - test not performed");
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:41,代码来源:DigestInputStreamTest.java

示例6: testReadbyteArrayintint05

import java.security.DigestInputStream; //导入方法依赖的package包/类
/**
 * Test #5 for <code>read(byte[],int,int)</code> method<br>
 *
 * Assertion: returns the number of bytes read<br>
 *
 * Assertion: put bytes read into specified array at specified offset<br>
 *
 * Assertion: does not update associated digest if
 * digest functionality is off<br>
 */
@TestTargetNew(
    level = TestLevel.PARTIAL_COMPLETE,
    method = "read",
    args = {byte[].class, int.class, int.class}
)
public final void testReadbyteArrayintint05()
    throws IOException {
    // check precondition
    assertEquals(0, MY_MESSAGE_LEN % CHUNK_SIZE);

    for (int ii=0; ii<algorithmName.length; ii++) {
        try {
            MessageDigest md = MessageDigest.getInstance(algorithmName[ii]);
            InputStream is = new ByteArrayInputStream(myMessage);
            DigestInputStream dis = new DigestInputStream(is, md);
            byte[] bArray = new byte[MY_MESSAGE_LEN];

            // turn digest off
            dis.on(false);

            for (int i=0; i<MY_MESSAGE_LEN/CHUNK_SIZE; i++) {
                dis.read(bArray, i*CHUNK_SIZE, CHUNK_SIZE);
            }
            // check that digest has not been updated
            assertTrue(Arrays.equals(dis.getMessageDigest().digest(),
                    MDGoldenData.getDigest(algorithmName[ii]+"_NU")));
            return;
        } catch (NoSuchAlgorithmException e) {
            // allowed failure
        }
    }
    fail(getName() + ": no MessageDigest algorithms available - test not performed");
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:44,代码来源:DigestInputStreamTest.java

示例7: testRead06

import java.security.DigestInputStream; //导入方法依赖的package包/类
/**
 * Test #6 for <code>read()</code> method<br>
 * Test #2 for <code>on(boolean)</code> method<br>
 * 
 * Assertion: broken <code>DigestInputStream</code>instance:
 * associated <code>MessageDigest</code> not set.
 * <code>read()</code> must work when digest
 * functionality is off
 */
public final void testRead06()
    throws IOException {
    InputStream is = new ByteArrayInputStream(myMessage);
    // construct object without digest
    DigestInputStream dis = new DigestInputStream(is, null);
    // set digest functionality to off
    dis.on(false);
    // the following must pass without any exception
    for (int i=0; i<MY_MESSAGE_LEN; i++) {
        assertTrue((byte)dis.read() == myMessage[i]);
    }
}
 
开发者ID:shannah,项目名称:cn1,代码行数:22,代码来源:DigestInputStreamTest.java

示例8: testReadbyteArrayintint05

import java.security.DigestInputStream; //导入方法依赖的package包/类
/**
 * Test #5 for <code>read(byte[],int,int)</code> method<br>
 * 
 * Assertion: returns the number of bytes read<br>
 * 
 * Assertion: put bytes read into specified array at specified offset<br>
 * 
 * Assertion: does not update associated digest if
 * digest functionality is off<br>
 */
public final void testReadbyteArrayintint05()
    throws IOException {
    // check precondition
    assertEquals(0, MY_MESSAGE_LEN % CHUNK_SIZE);
    
    for (int ii=0; ii<algorithmName.length; ii++) {
        try {
            MessageDigest md = MessageDigest.getInstance(algorithmName[ii]);
            InputStream is = new ByteArrayInputStream(myMessage);
            DigestInputStream dis = new DigestInputStream(is, md);
            byte[] bArray = new byte[MY_MESSAGE_LEN];
            
            // turn digest off
            dis.on(false);
            
            for (int i=0; i<MY_MESSAGE_LEN/CHUNK_SIZE; i++) {
                dis.read(bArray, i*CHUNK_SIZE, CHUNK_SIZE);
            }
            // check that digest has not been updated
            assertTrue(Arrays.equals(dis.getMessageDigest().digest(),
                    MDGoldenData.getDigest(algorithmName[ii]+"_NU")));
            return;
        } catch (NoSuchAlgorithmException e) {
            // allowed failure
        }
    }
    fail(getName() + ": no MessageDigest algorithms available - test not performed");
}
 
开发者ID:shannah,项目名称:cn1,代码行数:39,代码来源:DigestInputStreamTest.java

示例9: testOn

import java.security.DigestInputStream; //导入方法依赖的package包/类
/**
 * Test for <code>on()</code> method<br>
 * Assertion: turns digest functionality on or off
 */
public final void testOn() throws IOException {
    for (int ii=0; ii<algorithmName.length; ii++) {
        try {
            MessageDigest md = MessageDigest.getInstance(algorithmName[ii]);
            InputStream is = new ByteArrayInputStream(myMessage);
            DigestInputStream dis = new DigestInputStream(is, md);
            
            // turn digest off
            dis.on(false);
            
            for (int i=0; i<MY_MESSAGE_LEN-1; i++) {
                dis.read();
            }
            
            // turn digest on
            dis.on(true);
            
            // read remaining byte
            dis.read();
            
            byte[] digest = dis.getMessageDigest().digest();
            
            // check that digest value has been
            // updated by the last read() call
            assertFalse(
                    Arrays.equals(digest,MDGoldenData.getDigest(algorithmName[ii])) ||
                    Arrays.equals(digest,MDGoldenData.getDigest(algorithmName[ii]+"_NU")));
            return;
        } catch (NoSuchAlgorithmException e) {
            // allowed failure
        }
    }
    fail(getName() + ": no MessageDigest algorithms available - test not performed");
}
 
开发者ID:shannah,项目名称:cn1,代码行数:39,代码来源:DigestInputStreamTest.java

示例10: testOn

import java.security.DigestInputStream; //导入方法依赖的package包/类
/**
 * Test for <code>on()</code> method<br>
 * Assertion: turns digest functionality on or off
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "on",
    args = {boolean.class}
)
public final void testOn() throws IOException {
    for (int ii=0; ii<algorithmName.length; ii++) {
        try {
            MessageDigest md = MessageDigest.getInstance(algorithmName[ii]);
            InputStream is = new ByteArrayInputStream(myMessage);
            DigestInputStream dis = new DigestInputStream(is, md);

            // turn digest off
            dis.on(false);

            for (int i=0; i<MY_MESSAGE_LEN-1; i++) {
                dis.read();
            }

            // turn digest on
            dis.on(true);

            // read remaining byte
            dis.read();

            byte[] digest = dis.getMessageDigest().digest();

            // check that digest value has been
            // updated by the last read() call
            assertFalse(
                    Arrays.equals(digest,MDGoldenData.getDigest(algorithmName[ii])) ||
                    Arrays.equals(digest,MDGoldenData.getDigest(algorithmName[ii]+"_NU")));
            return;
        } catch (NoSuchAlgorithmException e) {
            // allowed failure
        }
    }
    fail(getName() + ": no MessageDigest algorithms available - test not performed");
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:45,代码来源:DigestInputStreamTest.java


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