⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mactest.java

📁 一个java开发的非常全面的关于证书发放
💻 JAVA
字号:
/*
  Name:         MacTest.java
  Licensing:    LGPL

  API:          Sun (http://java.sun.com) JCE 1.2.2 API (cleanroom implementation by Bouncy Castle)
  Provider:     Bouncy Castle (http://www.bouncycastle.org)

  Disclaimer:

  COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY OF ANY KIND,
  EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES THAT THE COVERED CODE
  IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR NON-INFRINGING. THE ENTIRE
  RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED CODE IS WITH YOU. SHOULD ANY COVERED CODE
  PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR)
  ASSUME THE COST OF ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY
  CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED
  HEREUNDER EXCEPT UNDER THIS DISCLAIMER.

  (C) Copyright 2003 Gert Van Ham
*/

package net.sourceforge.jcetaglib.test;

import junit.framework.Assert;
import junit.framework.TestCase;
import net.sourceforge.jcetaglib.lib.Macs;

import java.io.DataOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * A collection of blockcipher MAC tests
 * <P>
 * These tests can be run using JUnit (http://www.junit.org)
 *
 * @author Gert Van Ham
 * @author hamgert@users.sourceforge.net
 * @author http://jcetaglib.sourceforge.net
 * @version $Id: MacTest.java,v 1.1 2003/12/28 19:06:57 hamgert Exp $
 */
public class MacTest extends TestCase {
    private StringBuffer mac1 = null;
    private StringBuffer mac2 = null;

    /**
     * setup test
     *
     * @throws java.io.IOException
     */
    protected void setUp() throws IOException {
        // create text file
        FileOutputStream outStr = new FileOutputStream(RunTest.TEMPFOLDER + "readable.txt");
        DataOutputStream dataStr = new DataOutputStream(outStr);

        dataStr.writeBytes("This is a readable string inside a file");

        dataStr.flush();
        dataStr.close();

        outStr.close();
    }

    /**
     * test MAC
     *
     * @throws Exception
     */
    public void testMac() throws Exception {
        for (int i = 0; i < RunTest.macalg.length; i++) {
            for (int j = 0; j < RunTest.text.length; j++) {

                mac1 = Macs.generateMAC(RunTest.text[j], RunTest.TEMPFOLDER + RunTest.macalg[i][1], new StringBuffer("password"), RunTest.alg[i][0], RunTest.macalg[i][0]);
                mac2 = Macs.generateMAC(RunTest.text[j], RunTest.TEMPFOLDER + RunTest.macalg[i][1], new StringBuffer("password"), RunTest.alg[i][0], RunTest.macalg[i][0]);

                Assert.assertEquals(mac1.toString(), mac2.toString());
            }
        }
    }

    /**
     * test file MAC
     *
     * @throws Exception
     */
    public void testFileMac() throws Exception {
        for (int i = 0; i < RunTest.macalg.length; i++) {

            mac1 = Macs.generateFileMAC(RunTest.TEMPFOLDER + "readable.txt", RunTest.TEMPFOLDER + RunTest.macalg[i][1], new StringBuffer("password"), RunTest.alg[i][0], RunTest.macalg[i][0]);
            mac2 = Macs.generateFileMAC(RunTest.TEMPFOLDER + "readable.txt", RunTest.TEMPFOLDER + RunTest.macalg[i][1], new StringBuffer("password"), RunTest.alg[i][0], RunTest.macalg[i][0]);

            Assert.assertEquals(mac1.toString(), mac2.toString());

        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -