Package java.security

Examples of java.security.DigestInputStream


     * <code>read()</code> must not work when digest
     * functionality is on
     */
    public final void testRead05() {
        InputStream is = new ByteArrayInputStream(myMessage);
        DigestInputStream dis = new DigestInputStream(is, null);

        // must result in an exception
        try {
            for (int i=0; i<MY_MESSAGE_LEN; i++) {
                dis.read();
            }
            fail("read() must not work when digest functionality is on");
        } catch (Exception e) {
        }
    }
View Full Code Here


     */
    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]);
        }
    }
View Full Code Here

        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);
                byte[] bArray = new byte[MY_MESSAGE_LEN];
               
                // check that read(byte[],int,int) returns valid value
                assertTrue("retval",
                        dis.read(bArray, 0, bArray.length) == MY_MESSAGE_LEN);
                // check that bArray has been filled properly
                assertTrue("bArray", Arrays.equals(myMessage, bArray));
                // check that associated digest has been updated properly
                assertTrue("update", Arrays.equals(dis.getMessageDigest().digest(),
                        MDGoldenData.getDigest(algorithmName[ii])));
                return;
            } catch (NoSuchAlgorithmException e) {
                // allowed failure
            }
View Full Code Here

       
        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];
               
                for (int i=0; i<MY_MESSAGE_LEN/CHUNK_SIZE; i++) {
                    // check that read(byte[],int,int) returns valid value
                    assertTrue("retval",
                            dis.read(bArray, i*CHUNK_SIZE, CHUNK_SIZE) == CHUNK_SIZE);
                }
                // check that bArray has been filled properly
                assertTrue("bArray", Arrays.equals(myMessage, bArray));
                // check that associated digest has been updated properly
                assertTrue("update", Arrays.equals(dis.getMessageDigest().digest(),
                        MDGoldenData.getDigest(algorithmName[ii])));
                return;
            } catch (NoSuchAlgorithmException e) {
                // allowed failure
            }
View Full Code Here

       
        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];
               
                for (int i=0; i<MY_MESSAGE_LEN/(CHUNK_SIZE+1); i++) {
                    // check that read(byte[],int,int) returns valid value
                    assertTrue("retval1",
                            dis.read(bArray, i*(CHUNK_SIZE+1), CHUNK_SIZE+1) ==
                                CHUNK_SIZE + 1);
                }
               
                // check that last call returns right
                // number of remaining bytes
                assertTrue("retval2",
                        dis.read(bArray,
                                MY_MESSAGE_LEN/(CHUNK_SIZE+1)*(CHUNK_SIZE+1),
                                MY_MESSAGE_LEN % (CHUNK_SIZE+1)) ==
                                    (MY_MESSAGE_LEN % (CHUNK_SIZE+1)));
               
                // check that bArray has been filled properly
                assertTrue("bArray", Arrays.equals(myMessage, bArray));
                // check that associated digest has been updated properly
                assertTrue("update", Arrays.equals(dis.getMessageDigest().digest(),
                        MDGoldenData.getDigest(algorithmName[ii])));
                return;
            } catch (NoSuchAlgorithmException e) {
                // allowed failure
            }
View Full Code Here

        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);
                byte[] bArray = new byte[MY_MESSAGE_LEN];
                // read all but EOS
                dis.read(bArray, 0, bArray.length);
                // check that subsequent read(byte[],int,int) calls return -1 (EOS)
                assertEquals("retval1", -1, dis.read(bArray, 0, 1));
                assertEquals("retval2", -1, dis.read(bArray, 0, bArray.length));
                assertEquals("retval3", -1, dis.read(bArray, 0, 1));
                // check that 3 previous read() calls did not update digest
                assertTrue("update",
                        Arrays.equals(dis.getMessageDigest().digest(),
                                MDGoldenData.getDigest(algorithmName[ii])));
                return;
            } catch (NoSuchAlgorithmException e) {
                // allowed failure
            }
View Full Code Here

       
        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
            }
View Full Code Here

     */
    public final void testGetMessageDigest() {
        for (int ii=0; ii<algorithmName.length; ii++) {
            try {
                MessageDigest md = MessageDigest.getInstance(algorithmName[ii]);
                DigestInputStream dis = new DigestInputStream(null, md);
               
                assertTrue(dis.getMessageDigest() == md);
                return;
            } catch (NoSuchAlgorithmException e) {
                // allowed failure
            }
        }
View Full Code Here

     * Assertion: set associated message digest<br>
     */
    public final void testSetMessageDigest() {
        for (int ii=0; ii<algorithmName.length; ii++) {
            try {
                DigestInputStream dis = new DigestInputStream(null, null);
                MessageDigest md = MessageDigest.getInstance(algorithmName[ii]);
                dis.setMessageDigest(md);
               
                assertTrue(dis.getMessageDigest() == md);
                return;
            } catch (NoSuchAlgorithmException e) {
                // allowed failure
            }
        }
View Full Code Here

    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])) ||
View Full Code Here

TOP

Related Classes of java.security.DigestInputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.