一种简单的加密算法

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package javax.crypto.spec;

import java.security.spec.KeySpec;
import java.util.Arrays;
import javax.crypto.SecretKey;

public class SecretKeySpec implements KeySpec, SecretKey {
    private static final long serialVersionUID = 6577238317307289933L;
    private byte[] key;
    private String algorithm;

    public SecretKeySpec(byte[] var1, String var2) {
        if(var1 != null && var2 != null) {
            if(var1.length == 0) {
                throw new IllegalArgumentException("Empty key");
            } else {
                this.key = (byte[])((byte[])var1.clone());
                this.algorithm = var2;
            }
        } else {
            throw new IllegalArgumentException("Missing argument");
        }
    }

    public SecretKeySpec(byte[] var1, int var2, int var3, String var4) {
        if(var1 != null && var4 != null) {
            if(var1.length == 0) {
                throw new IllegalArgumentException("Empty key");
            } else if(var1.length - var2 < var3) {
                throw new IllegalArgumentException("Invalid offset/length combination");
            } else if(var3 < 0) {
                throw new ArrayIndexOutOfBoundsException("len is negative");
            } else {
                this.key = new byte[var3];
                System.arraycopy(var1, var2, this.key, 0, var3);
                this.algorithm = var4;
            }
        } else {
            throw new IllegalArgumentException("Missing argument");
        }
    }

    public String getAlgorithm() {
        return this.algorithm;
    }

    public String getFormat() {
        return "RAW";
    }

    public byte[] getEncoded() {
        return (byte[])((byte[])this.key.clone());
    }

    public int hashCode() {
        int var1 = 0;

        for(int var2 = 1; var2 < this.key.length; ++var2) {
            var1 += this.key[var2] * var2;
        }

        return this.algorithm.equalsIgnoreCase("TripleDES")?var1 ^ "desede".hashCode():var1 ^ this.algorithm.toLowerCase().hashCode();
    }

    public boolean equals(Object var1) {
        if(this == var1) {
            return true;
        } else if(!(var1 instanceof SecretKey)) {
            return false;
        } else {
            String var2 = ((SecretKey)var1).getAlgorithm();
            if(var2.equalsIgnoreCase(this.algorithm) || var2.equalsIgnoreCase("DESede") && this.algorithm.equalsIgnoreCase("TripleDES") || var2.equalsIgnoreCase("TripleDES") && this.algorithm.equalsIgnoreCase("DESede")) {
                byte[] var3 = ((SecretKey)var1).getEncoded();
                return Arrays.equals(this.key, var3);
            } else {
                return false;
            }
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值