Hellow
- 折叠区的练习
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package com.sun.crypto.provider;
import java.nio.ByteBuffer;
import java.security.AlgorithmParameters;
import java.security.GeneralSecurityException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import java.security.ProviderException;
import java.security.SecureRandom;
import java.security.spec.AlgorithmParameterSpec;
import javax.crypto.BadPaddingException;
import javax.crypto.CipherSpi;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.ShortBufferException;
abstract class AESCipher extends CipherSpi {
private CipherCore core = null;
private final int fixedKeySize;
private boolean updateCalled;
static final void checkKeySize(Key key, int fixedKeySize) throws InvalidKeyException {
if (fixedKeySize != -1) {
if (key == null) {
throw new InvalidKeyException("The key must not be null");
}
byte[] value = key.getEncoded();
if (value == null) {
throw new InvalidKeyException("Key encoding must not be null");
}
if (value.length != fixedKeySize) {
throw new InvalidKeyException("The key must be " + fixedKeySize + " bytes");
}
}
}
protected AESCipher(int keySize) {
this.core = new CipherCore(new AESCrypt(), 16);
this.fixedKeySize = keySize;
}
protected void engineSetMode(String mode) throws NoSuchAlgorithmException {
this.core.setMode(mode);
}
protected void engineSetPadding(String paddingScheme) throws NoSuchPaddingException {
this.core.setPadding(paddingScheme);
}
protected int engineGetBlockSize() {
return 16;
}
protected int engineGetOutputSize(int inputLen) {
return this.core.getOutputSize(inputLen);
}
protected byte[] engineGetIV() {
return this.core.getIV();
}
protected AlgorithmParameters engineGetParameters() {
return this.core.getParameters("AES");
}
protected void engineInit(int opmode, Key key, SecureRandom random) throws InvalidKeyException {
checkKeySize(key, this.fixedKeySize);
this.updateCalled = false;
this.core.init(opmode, key, random);
}
protected void engineInit(int opmode, Key key, AlgorithmParameterSpec params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException {
checkKeySize(key, this.fixedKeySize);
this.updateCalled = false;
this.core.init(opmode, key, params, random);
}
protected void engineInit(int opmode, Key key, AlgorithmParameters params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException {
checkKeySize(key, this.fixedKeySize);
this.updateCalled = false;
this.core.init(opmode, key, params, random);
}
protected byte[] engineUpdate(byte[] input, int inputOffset, int inputLen) {
this.updateCalled = true;
return this.core.update(input, inputOffset, inputLen);
}
protected int engineUpdate(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) throws ShortBufferException {
this.updateCalled = true;
return this.core.update(input, inputOffset, inputLen, output, outputOffset);
}
protected byte[] engineDoFinal(byte[] input, int inputOffset, int inputLen) throws IllegalBlockSizeException, BadPaddingException {
byte[] out = this.core.doFinal(input, inputOffset, inputLen);
this.updateCalled = false;
return out;
}
protected int engineDoFinal(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) throws IllegalBlockSizeException, ShortBufferException, BadPaddingException {
int outLen = this.core.doFinal(input, inputOffset, inputLen, output, outputOffset);
this.updateCalled = false;
return outLen;
}
protected int engineGetKeySize(Key key) throws InvalidKeyException {
byte[] encoded = key.getEncoded();
if (!AESCrypt.isKeySizeValid(encoded.length)) {
throw new InvalidKeyException("Invalid AES key length: " + encoded.length + " bytes");
} else {
return Math.multiplyExact(encoded.length, 8);
}
}
protected byte[] engineWrap(Key key) throws IllegalBlockSizeException, InvalidKeyException {
return this.core.wrap(key);
}
protected Key engineUnwrap(byte[] wrappedKey, String wrappedKeyAlgorithm, int wrappedKeyType) throws InvalidKeyException, NoSuchAlgorithmException {
return this.core.unwrap(wrappedKey, wrappedKeyAlgorithm, wrappedKeyType);
}
protected void engineUpdateAAD(byte[] src, int offset, int len) {
if (this.core.getMode() == 7 && this.updateCalled) {
throw new IllegalStateException("AAD must be supplied before encryption/decryption starts");
} else {
this.core.updateAAD(src, offset, len);
}
}
protected void engineUpdateAAD(ByteBuffer src) {
if (this.core.getMode() == 7 && this.updateCalled) {
throw new IllegalStateException("AAD must be supplied before encryption/decryption starts");
} else {
if (src != null) {
int aadLen = src.limit() - src.position();
if (aadLen > 0) {
if (src.hasArray()) {
int aadOfs = Math.addExact(src.arrayOffset(), src.position());
this.core.updateAAD(src.array(), aadOfs, aadLen);
src.position(src.limit());
} else {
byte[] aad = new byte[aadLen];
src.get(aad);
this.core.updateAAD(aad, 0, aadLen);
}
}
}
}
}
public static final class AES256_GCM_NoPadding extends AESCipher.OidImpl {
public AES256_GCM_NoPadding() {
super(32, "GCM", "NOPADDING");
}
}
public static final class AES192_GCM_NoPadding extends AESCipher.OidImpl {
public AES192_GCM_NoPadding() {
super(24, "GCM", "NOPADDING");
}
}
public static final class AES128_GCM_NoPadding extends AESCipher.OidImpl {
public AES128_GCM_NoPadding() {
super(16, "GCM", "NOPADDING");
}
}
public static final class AES256_CFB_NoPadding extends AESCipher.OidImpl {
public AES256_CFB_NoPadding() {
super(32, "CFB", "NOPADDING");
}
}
public static final class AES192_CFB_NoPadding extends AESCipher.OidImpl {
public AES192_CFB_NoPadding() {
super(24, "CFB", "NOPADDING");
}
}
public static final class AES128_CFB_NoPadding extends AESCipher.OidImpl {
public AES128_CFB_NoPadding() {
super(16, "CFB", "NOPADDING");
}
}
public static final class AES256_OFB_NoPadding extends AESCipher.OidImpl {
public AES256_OFB_NoPadding() {
super(32, "OFB", "NOPADDING");
}
}
public static final class AES192_OFB_NoPadding extends AESCipher.OidImpl {
public AES192_OFB_NoPadding() {
super(24, "OFB", "NOPADDING");
}
}
public static final class AES128_OFB_NoPadding extends AESCipher.OidImpl {
public AES128_OFB_NoPadding() {
super(16, "OFB", "NOPADDING");
}
}
public static final class AES256_CBC_NoPadding extends AESCipher.OidImpl {
public AES256_CBC_NoPadding() {
super(32, "CBC", "NOPADDING");
}
}
public static final class AES192_CBC_NoPadding extends AESCipher.OidImpl {
public AES192_CBC_NoPadding() {
super(24, "CBC", "NOPADDING");
}
}
public static final class AES128_CBC_NoPadding extends AESCipher.OidImpl {
public AES128_CBC_NoPadding() {
super(16, "CBC", "NOPADDING");
}
}
public static final class AES256_ECB_NoPadding extends AESCipher.OidImpl {
public AES256_ECB_NoPadding() {
super(32, "ECB", "NOPADDING");
}
}
public static final class AES192_ECB_NoPadding extends AESCipher.OidImpl {
public AES192_ECB_NoPadding() {
super(24, "ECB", "NOPADDING");
}
}
public static final class AES128_ECB_NoPadding extends AESCipher.OidImpl {
public AES128_ECB_NoPadding() {
super(16, "ECB", "NOPADDING");
}
}
abstract static class OidImpl extends AESCipher {
protected OidImpl(int keySize, String mode, String padding) {
super(keySize);
try {
this.engineSetMode(mode);
this.engineSetPadding(padding);
} catch (GeneralSecurityException var6) {
ProviderException pe = new ProviderException("Internal Error");
pe.initCause(var6);
throw pe;
}
}
}
public static final class General extends AESCipher {
public General() {
super(-1);
}
}
}