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

📄 hmac.java

📁 进行与数字证书相关开发必须的java源码
💻 JAVA
字号:
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   HMac.java

package jit.crypto.macs;

import jit.crypto.*;
import jit.crypto.params.KeyParameter;

public class HMac
    implements Mac
{

    private static final int BLOCK_LENGTH = 64;
    private static final byte IPAD = 54;
    private static final byte OPAD = 92;
    private Digest digest;
    private int digestSize;
    private byte inputPad[];
    private byte outputPad[];

    public HMac(Digest digest)
    {
        inputPad = new byte[64];
        outputPad = new byte[64];
        this.digest = digest;
        digestSize = digest.getDigestSize();
    }

    public String getAlgorithmName()
    {
        return String.valueOf(String.valueOf(digest.getAlgorithmName())).concat("/HMAC");
    }

    public Digest getUnderlyingDigest()
    {
        return digest;
    }

    public void init(CipherParameters params)
    {
        digest.reset();
        byte key[] = ((KeyParameter)params).getKey();
        if(key.length > 64)
        {
            digest.update(key, 0, key.length);
            digest.doFinal(inputPad, 0);
            for(int i = digestSize; i < inputPad.length; i++)
                inputPad[i] = 0;

        } else
        {
            System.arraycopy(key, 0, inputPad, 0, key.length);
            for(int i = key.length; i < inputPad.length; i++)
                inputPad[i] = 0;

        }
        outputPad = new byte[inputPad.length];
        System.arraycopy(inputPad, 0, outputPad, 0, inputPad.length);
        for(int i = 0; i < inputPad.length; i++)
            inputPad[i] ^= 0x36;

        for(int i = 0; i < outputPad.length; i++)
            outputPad[i] ^= 0x5c;

        digest.update(inputPad, 0, inputPad.length);
    }

    public int getMacSize()
    {
        return digestSize;
    }

    public void update(byte in)
    {
        digest.update(in);
    }

    public void update(byte in[], int inOff, int len)
    {
        digest.update(in, inOff, len);
    }

    public int doFinal(byte out[], int outOff)
    {
        byte tmp[] = new byte[digestSize];
        digest.doFinal(tmp, 0);
        digest.update(outputPad, 0, outputPad.length);
        digest.update(tmp, 0, tmp.length);
        int len = digest.doFinal(out, outOff);
        reset();
        return len;
    }

    public void reset()
    {
        digest.reset();
        digest.update(inputPad, 0, inputPad.length);
    }

    static 
    {
        BLOCK_LENGTH = 64;
        IPAD = 54;
        OPAD = 92;
    }
}

⌨️ 快捷键说明

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