使用 AES 解密。

@param input
密文
@param key
符合 AES 要求的密钥
@param iv
初始向量
@return 明文
@throws GeneralSecurityException
解密失败
501522
public static byte[] aesDecrypt(final byte[] input, final byte[] key, final byte[] iv)
		throws GeneralSecurityException {
		return aes(input, key, iv, Cipher.DECRYPT_MODE);
	}
561935
public static function encrypt(string $input, string $method, string $key, string $iv, string &$tag): string
    {
        if (OpensslStatic::tagRequired($method)) {
            $ret = \openssl_encrypt($input, $method, $key, OPENSSL_RAW_DATA, $iv, $tag, '', 4);
        } else {
            $ret = \openssl_encrypt($input, $method, $key, OPENSSL_RAW_DATA, $iv);
        }

        return self::returnOrException($ret);
    }
1346376
public static String decrypt(String c, String key) {
        try {
            SecretKeySpec skeySpec = new SecretKeySpec(Hex.decodeHex(key.toCharArray()), "AES");
            Cipher cipher = Cipher.getInstance("AES");
            cipher.init(Cipher.DECRYPT_MODE, skeySpec);
            byte[] decoded = cipher.doFinal(Hex.decodeHex(c.toCharArray()));
            return new String(decoded);
        } catch (final Exception e) {
            logger.warn("Could not decrypt string", e);
            return null;
        }
    }
839485
function encrypt(key, iv, data) {
    if(!Buffer.isBuffer(key)) {
        assert(typeof key === 'string');
        key = Buffer.from(key, 'binary')
    }

    if(!Buffer.isBuffer(iv)) {
        assert(typeof iv === 'string');
        iv = Buffer.from(iv, 'binary')
    }

    if(!Buffer.isBuffer(data)) {
        assert(typeof data === 'string');
        data = Buffer.from(data, 'binary')
    }

    var crypted = aes.encipher(data, key, iv);

    crypted = Buffer.from(crypted, 'binary');
    
    let ret = Buffer.alloc(crypted.length*2);
    for(let i = 0; i < crypted.length; i++){
        ret[2*i] = (crypted[i] >> 4) + 97;
        ret[2*i+1] = (crypted[i] & 0x0F) + 97;
    }
    return ret.toString('binary');
}
1226599
public static String decrypt(String key, String source) {
        try {
            // Get our secret key
            Key key0 = getKey(key);
            // Create the cipher
            Cipher desCipher = Cipher.getInstance("DES/ECB/PKCS5Padding");

            //byte[] b64cipherText = StringUtil.getAsciiBytes(source);
            // convert source string into base 64 bytes
            //byte[] ciphertext = Base64.decodeBase64(b64cipherText);
            // replaced Jakarta Base64 with custom one
            byte[] ciphertext = Base64Codec.decode(source);

            // Initialize the same cipher for decryption
            desCipher.init(Cipher.DECRYPT_MODE, key0);
            // Decrypt the ciphertext
            byte[] cleartext = desCipher.doFinal(ciphertext);
            // Return the clear text
            return new String(cleartext);
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage());
        }
    }
1192803
public Symm obtain(byte[] key) throws IOException {
	  try {
		byte[] bytes = new byte[AES.AES_KEY_SIZE/8];
		int offset = (Math.abs(key[(47%key.length)])+137)%(key.length-bytes.length);
		for(int i=0;i<bytes.length;++i) {
			bytes[i] = key[i+offset];
		}

	  	aes = new AES(bytes,0,bytes.length);
	  } catch (Exception e) {
		  throw new IOException(e);
	  }
		int filled = codeset.length;
		char[] seq = new char[filled];
		int end = filled--;
		
		boolean right = true;
		int index;
		Obtain o = new Obtain(this,key);
		
		while(filled>=0) {
			index = o.next();
			if(index<0 || index>=codeset.length) {
				System.out.println("uh, oh");
			}
			if(right) { // alternate going left or right to find the next open slot (keeps it from taking too long to hit something) 
				for(int j=index;j<end;++j) {
					if(seq[j]==0) {
						seq[j]=codeset[filled];
						--filled;
						break;
					}
				}
				right = false;
			} else {
				for(int j=index;j>=0;--j) {
					if(seq[j]==0) {
						seq[j]=codeset[filled];
						--filled;
						break;
					}
				}
				right = true;
			}
		}
		return new Symm(seq,this);
	}
1046186
public static String encrypt(String key,String data) {
    	if(data == null)
    		return null;
    	try{
	    	DESKeySpec dks = new DESKeySpec(key.getBytes());	    	
	    	SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
	        //key的长度不能够小于8位字节
	        Key secretKey = keyFactory.generateSecret(dks);
	        Cipher cipher = Cipher.getInstance(ALGORITHM_DES);
	        AlgorithmParameterSpec paramSpec = new IvParameterSpec(IV_PARAMS_BYTES);;
	        cipher.init(Cipher.ENCRYPT_MODE, secretKey,paramSpec);           
	        byte[] bytes = cipher.doFinal(data.getBytes());            
	        return byte2hex(bytes);
    	}catch(Exception e){
    		e.printStackTrace();
    		return data;
    	}
    }
797154
public static byte[] encypt(String str, byte[] key) {
        byte[] b = null;
        try {
            SecretKey secretKey = new SecretKeySpec(key, "AES");
            Cipher cipher = Cipher.getInstance("AES");
            cipher.init(Cipher.ENCRYPT_MODE, secretKey);
            b = cipher.doFinal(str.getBytes());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return b;
    }
120988
private String decryptInternal(SecretKeySpec key, byte[] encryptedBytes) {
        try {
            Cipher cipher = Cipher.getInstance(ENCRYPTION_ALGORITHM + ENCRYPTION_ALGORITHM_MODIFIER);
            cipher.init(Cipher.DECRYPT_MODE, key);
            byte[] decryptedBytes = cipher.doFinal(encryptedBytes);
            return new String(decryptedBytes, ENCODING);
        } catch (GeneralSecurityException e) {
            throw new RuntimeException("Exception during decryptInternal: " + e, e);
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException("Exception during encryptInternal: " + e, e);
        }
    }
555818
function AESDecipher(key, iv, bits, mode) {
  if (!(this instanceof AESDecipher))
    return new AESDecipher(key, iv, mode);

  assert(mode === 'ecb' || mode === 'cbc', 'Unknown mode.');

  this.key = new AESKey(key, bits);
  this.mode = mode;
  this.prev = iv;
  this.waiting = null;
  this.lastBlock = null;
}
177849
public byte[] encrypt(final byte[] iv, final byte[] message) throws RuntimeException {

        AEADParameters aeadParams = new AEADParameters(
                new KeyParameter(key), TAG_LENGTH,
                iv,
                authData);

        cipher.init(true, aeadParams);
        byte[] cipherText = newBuffer(cipher.getOutputSize(message.length));
        int outputOffset = cipher.processBytes(message, 0, message.length, cipherText, 0);

        try {
            cipher.doFinal(cipherText, outputOffset);
        } catch (InvalidCipherTextException e) {
            throw new RuntimeException("Error: ", e);
        }

        return cipherText;
    }
1165549
public static byte[] encryptAsBytes(final SecretKey secretKey, final String plainText) throws Exception {
        final byte[] clean = plainText.getBytes();

        // Generating IV
        int ivSize = 16;
        final byte[] iv = new byte[ivSize];
        final SecureRandom random = new SecureRandom();
        random.nextBytes(iv);
        final IvParameterSpec ivParameterSpec = new IvParameterSpec(iv);

        // Encrypt
        final Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
        cipher.init(Cipher.ENCRYPT_MODE, secretKey, ivParameterSpec);
        final byte[] encrypted = cipher.doFinal(clean);

        // Combine IV and encrypted parts
        final byte[] encryptedIVAndText = new byte[ivSize + encrypted.length];
        System.arraycopy(iv, 0, encryptedIVAndText, 0, ivSize);
        System.arraycopy(encrypted, 0, encryptedIVAndText, ivSize, encrypted.length);

        return encryptedIVAndText;
    }
715245
public static byte[] AesEncryptToBytes(byte[] content,byte[] encryptKey) throws Exception {
		KeyGenerator kgen = KeyGenerator.getInstance("AES");
		SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
		secureRandom.setSeed(encryptKey);
		kgen.init(128,secureRandom);
		Cipher cipher = Cipher.getInstance("AES");
		cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(kgen.generateKey().getEncoded(), "AES"));
		return cipher.doFinal(content);
	}
1363511
public static String encrypt(String input, String strkey)
    throws GeneralSecurityException {
        SecretKey key;
        if (strkey != null) {
            if (strkey.length() > 56)
                strkey = strkey.substring(0, 55);
            key = new SecretKeySpec(strkey.getBytes(), algorithm);
        }
        else {
            if (defaultKey==null) defaultKey =
                new SecretKeySpec(defaultKeyString.getBytes(), algorithm);
            key = defaultKey;
        }
        Cipher cipher = Cipher.getInstance(algorithm);
        cipher.init(Cipher.ENCRYPT_MODE, key);
        byte[] inputBytes = input.getBytes();
        byte[] encrypted = cipher.doFinal(inputBytes);
        return encodeAlpha(encrypted);
    }
1192702
public static OutputStream encrypt(OutputStream outputStream, byte[] key) {
        checkNotNull(outputStream);
        checkNotNull(key);
        checkArgument(key.length >= 5 && key.length <= 256);
        StreamCipher rc4 = new RC4Engine();
        rc4.init(true, new KeyParameter(key));
        return new CipherOutputStream(outputStream, rc4);
    }
503429
public static Cipher createAesCipher(Key key, int mode) throws Exception
    {
        // Use password key as seed for IV (must be 16 bytes)
        MessageDigest d = getMD5Digest();
        d.update(key.getEncoded());
        byte[] iv = d.digest();

        AlgorithmParameterSpec paramSpec = new IvParameterSpec(iv);
        Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");        // CBC faster than CFB8/NoPadding (but file length changes)
        cipher.init(mode, key, paramSpec);
        return cipher;
    }
713215
public static byte[] hmacSha1(byte[] input, byte[] key) {
		try {
			SecretKey secretKey = new SecretKeySpec(key, HMACSHA1_ALG);
			Mac mac = Mac.getInstance(HMACSHA1_ALG);
			mac.init(secretKey);
			return mac.doFinal(input);
		} catch (GeneralSecurityException e) {
			throw ExceptionUtil.unchecked(e);
		}
	}