亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? aes.java

?? 對稱加密算法
?? JAVA
字號:
 /***

 Copyright 2006 bsmith@qq.com

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.

 */


package org.bsmith.crypto;

import java.io.UnsupportedEncodingException;

import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.ShortBufferException;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;

import org.bsmith.encoding.Base16;


/**
 * aes chiper class.
 * CBC mode with PKCS#1 v1.5 padding.
 */
public class AES
{
    public static void dump(String label, byte[] data)
    {
        String hex_str = Base16.encode(data);
        System.out.println(label+"="+hex_str);
    }

    public static void main(String[] args) throws UnsupportedEncodingException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, ShortBufferException, IllegalBlockSizeException, BadPaddingException, InvalidAlgorithmParameterException
    {
        System.out.println("=======================AES/CBC/PKCS5Padding=====================");
        // key
        byte[] key = "0123456789abcdef".getBytes("UTF-8");
        dump("key", key);
        // iv
        byte[] iv = "fedcba9876543210".getBytes("UTF-8");
        dump("iv", iv);
        
        byte[] indata = "bsmith is a good guy.".getBytes("UTF-8");
        dump("indata", indata);
        
        AES aes = new AES();
        aes.init(key, iv);
        byte[] outdata = aes.encrypt(indata);
        dump("outdata", outdata);
        
        byte[] indata1 = aes.decrypt(outdata);
        dump("indata1", indata1);
    }

    private Cipher enc;
    private Cipher dec;
    private SecretKeySpec keySpec;
    private IvParameterSpec ivSpec;

    public AES()
    {
    }
    
    /**
     * init the AES key.
     * the key must be 128, 192, or 256 bits.
     * @param key the AES key.
     * @param keyoff the AES key offset.
     * @param keylen the AES key length, the key length must be 16 bytes because SunJCE only support 16 bytes key.
     * @param iv the IV for CBC, the length of iv must be 16 bytes.
     * @param ivoff the iv offset.
     */
    public void init(byte[] key, int keyoff, int keylen, byte[] iv, int ivoff)
    {
        keySpec = new SecretKeySpec(key, keyoff, keylen, "AES");
        ivSpec = new IvParameterSpec(iv, ivoff, 16);
    }
    
    /**
     * init the AES key.
     * the key must be 16 bytes, because SunJCE only support 16 bytes key..
     * @param key the AES key.
     * @param iv the iv for CBC, iv must be 16 bytes length.
     */
    public void init(byte[] key, byte[] iv)
    {
        keySpec = new SecretKeySpec(key, "AES");
        ivSpec = new IvParameterSpec(iv);
    }
    
    /**
    * get the maximal cipher data length after encrypted.
    * @param len the plain data length.
    * @return the cipher data length.
    */
    public int getCipherLen(int len)
    {
        // for PKCS#1 v1.5 padding
        // max padding BLOCK_SIZE=16.
        int pad = len%16;
        if (0 == pad)
        {
            return len + 16;
        }
        return len - pad + 16;
    }
    
    /**
     * encrypt the input data to output data.
     * the input data length must be the times of 16 bytes.
     * and the output data length is equals to the input data.
     * @param indata the input data.
     * @param inoff the input data offset.
     * @param inlen the input data length.
     * @param outdata the output data.
     * @param outoff the output data offset.
     */
    public void encrypt(byte[] indata, int inoff, int inlen, byte[] outdata, int outoff) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, ShortBufferException, IllegalBlockSizeException, BadPaddingException, InvalidAlgorithmParameterException
    {
        initEncryptor();
        enc.doFinal(indata, inoff, inlen, outdata, outoff);
    }
    
    /**
     * encrypt the input data to output data.
     * @param indata the input data.
     * @param inoff the input data offset.
     * @param inlen the input data length.
     * @return the output encrypted data.
     */
    public byte[] encrypt(byte[] indata, int inoff, int inlen) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, ShortBufferException, IllegalBlockSizeException, BadPaddingException, InvalidAlgorithmParameterException
    {
        initEncryptor();
        return enc.doFinal(indata, inoff, inlen);
    }
    
    /**
     * encrypt the input data to output data.
     * @param indata the input data.
     * @return the output data.
     * @throws NoSuchAlgorithmException
     * @throws NoSuchPaddingException
     * @throws InvalidKeyException
     * @throws InvalidAlgorithmParameterException
     * @throws IllegalBlockSizeException
     * @throws BadPaddingException
     */
    public byte[] encrypt(byte[] indata) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException
    {
        initEncryptor();
        return enc.doFinal(indata);
    }
    
    /**
    * the maximal plain data length after decrypted.
    * @param len the cipher data length that will be decrypted.
    * @return the maximal plain data length.
    */
    public int getPlainLen(int len)
    {
        // for PKCS#1 v1.5 padding
        // len always be times of BLOCK_SIZE=16.
        return len;
    }
    
    /**
     * decrypt the input data to output data.
     * @param indata the input data.
     * @param inoff the input data offset.
     * @param inlen the input data length.
     * @param outdata the output data.
     * @param outoff the output data offset.
     */
    public void decrypt(byte[] indata, int inoff, int inlen, byte[] outdata, int outoff) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, ShortBufferException, IllegalBlockSizeException, BadPaddingException, InvalidAlgorithmParameterException
    {
        initDecryptor();
        dec.doFinal(indata, inoff, inlen, outdata, outoff);
    }
    
    /**
     * decrypt the input data to output data.
     * @param indata the input data.
     * @param inoff the input data offset.
     * @param inlen the input data length.
     * @return the output decrypted data.
     */
    public byte[] decrypt(byte[] indata, int inoff, int inlen) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException, ShortBufferException, InvalidAlgorithmParameterException
    {
        initDecryptor();
        return dec.doFinal(indata, inoff, inlen);
    }
    
    /**
     * decrypt the input data to output data.
     * @param indata the input cipher data.
     * @return the output plain data.
     * @throws NoSuchAlgorithmException
     * @throws NoSuchPaddingException
     * @throws InvalidKeyException
     * @throws InvalidAlgorithmParameterException
     * @throws IllegalBlockSizeException
     * @throws BadPaddingException
     */
    public byte[] decrypt(byte[] indata) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException
    {
        initDecryptor();
        return dec.doFinal(indata);
    }
    
    private void initEncryptor() throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException
    {
        if (null == enc)
        {
            enc = Cipher.getInstance("AES/CBC/PKCS5Padding");
            enc.init(Cipher.ENCRYPT_MODE, keySpec, ivSpec);
        }
    }
    
    private void initDecryptor() throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException
    {
        if (null == dec)
        {
            dec = Cipher.getInstance("AES/CBC/PKCS5Padding");
            dec.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);
        }
    }
}


?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
99精品视频中文字幕| 欧美在线一区二区三区| 亚洲欧美日韩久久精品| 制服丝袜激情欧洲亚洲| 成人免费视频一区二区| 日本一不卡视频| 亚洲欧美日韩在线不卡| 久久先锋影音av鲁色资源网| 欧美三级在线看| 国产69精品久久99不卡| 视频一区中文字幕| 亚洲欧洲另类国产综合| 亚洲精品一区二区三区影院| 欧美男人的天堂一二区| 色综合久久九月婷婷色综合| 国产成人在线看| 免费看日韩精品| 午夜视频在线观看一区二区| 亚洲麻豆国产自偷在线| 国产人成亚洲第一网站在线播放 | 宅男在线国产精品| 99国产精品久久久久久久久久 | 国产不卡视频一区二区三区| 日韩不卡免费视频| 亚洲成av人片在线| 亚洲精品乱码久久久久久 | 一区二区在线观看视频| 欧美国产欧美综合| 久久九九国产精品| 久久久99精品免费观看| 久久综合久久综合亚洲| 日韩欧美国产不卡| 日韩三区在线观看| 日韩欧美国产系列| 日韩免费观看2025年上映的电影| 这里只有精品免费| 91超碰这里只有精品国产| 欧美日韩国产精品成人| 欧美日韩一区中文字幕| 欧美日韩大陆一区二区| 欧美精选一区二区| 欧美精品一卡两卡| 欧美精品日日鲁夜夜添| 欧美日韩视频在线第一区 | 国产午夜精品久久久久久久| 国产丝袜欧美中文另类| 国产日韩欧美综合在线| 国产精品久久久久久久久免费桃花 | 国产高清成人在线| 成人午夜激情影院| 成人国产精品免费| fc2成人免费人成在线观看播放| 成人高清在线视频| 色狠狠桃花综合| 欧美日韩亚洲丝袜制服| 日韩欧美在线综合网| 久久久一区二区| 中文字幕制服丝袜一区二区三区| 亚洲婷婷在线视频| 亚洲h在线观看| 国内偷窥港台综合视频在线播放| 国产精品伊人色| 91麻豆精品视频| 在线不卡中文字幕播放| 欧美精品一区二区三区高清aⅴ| 久久久久久久性| 亚洲视频在线观看三级| 亚洲超碰97人人做人人爱| 老司机午夜精品99久久| 成人免费三级在线| 欧美色男人天堂| 欧美精品一区二区三区蜜桃| 综合欧美亚洲日本| 日韩黄色片在线观看| 国产麻豆视频精品| 欧美在线视频你懂得| 日韩免费看的电影| 亚洲少妇中出一区| 青青草国产成人av片免费| 国产成人激情av| 欧美老女人在线| 国产亚洲成av人在线观看导航| 亚洲综合另类小说| 国产一区二区三区| 精品视频在线免费| 国产日韩欧美麻豆| 无吗不卡中文字幕| av资源网一区| 日韩一级高清毛片| 亚洲欧美日韩一区二区| 国产自产v一区二区三区c| 在线一区二区三区四区五区| 欧美精品一区二区三区很污很色的 | 在线观看亚洲精品视频| 久久久久97国产精华液好用吗| 亚洲国产综合视频在线观看| 国产91对白在线观看九色| 欧美一区二区久久久| 最新久久zyz资源站| 国模冰冰炮一区二区| 在线观看欧美精品| 国产精品嫩草99a| 九色综合狠狠综合久久| 欧美主播一区二区三区美女| 亚洲国产精品成人综合色在线婷婷| 日韩福利视频导航| 91精品福利视频| 国产精品久久久久久一区二区三区| 另类成人小视频在线| 欧美日韩精品三区| 一区二区三区欧美在线观看| 粉嫩一区二区三区性色av| 精品久久久久久综合日本欧美| 亚洲国产你懂的| 色综合天天综合网国产成人综合天 | 99在线精品一区二区三区| 久久久亚洲精品一区二区三区 | 91免费观看视频| 国产女同互慰高潮91漫画| 另类综合日韩欧美亚洲| 欧美久久免费观看| 亚洲一区二区三区中文字幕在线| 91视频观看免费| 国产精品国产三级国产普通话蜜臀| 国产精品一线二线三线| 欧美xxxxxxxx| 免费成人在线播放| 欧美高清性hdvideosex| 日韩黄色免费网站| 欧美久久一区二区| 日韩不卡手机在线v区| 欧美精品久久久久久久多人混战| 亚洲成av人片| 欧美肥妇毛茸茸| 免费看欧美美女黄的网站| 91麻豆精品国产91久久久资源速度| 亚洲国产精品嫩草影院| 欧美日韩久久久一区| 亚洲va天堂va国产va久| 91精品在线免费观看| 美腿丝袜亚洲综合| 欧美精品一区二区三区在线播放| 国产综合一区二区| 国产欧美综合在线观看第十页| 成人一区二区视频| 国产精品国产自产拍在线| 一本一本久久a久久精品综合麻豆| 亚洲人午夜精品天堂一二香蕉| 91久久精品一区二区三区| 伊人开心综合网| 制服.丝袜.亚洲.另类.中文| 免费成人在线网站| 国产视频在线观看一区二区三区 | 福利电影一区二区三区| 国产精品三级视频| 色综合天天综合色综合av| 亚洲成av人综合在线观看| 337p亚洲精品色噜噜噜| 国内成人免费视频| 亚洲国产精品成人综合 | 91在线云播放| 午夜私人影院久久久久| 精品免费一区二区三区| 成人手机在线视频| 亚洲激情图片小说视频| 91精品国产综合久久精品麻豆| 国产在线精品一区在线观看麻豆| 国产欧美一区二区三区在线老狼 | 久久久久亚洲综合| 波多野结衣在线aⅴ中文字幕不卡| 亚洲乱码日产精品bd| 91精品国产色综合久久不卡电影 | 欧美影院一区二区三区| 美女视频黄 久久| 国产精品久久久久久久久搜平片 | 国产精品第五页| 在线不卡中文字幕| 成人白浆超碰人人人人| 丝袜亚洲另类欧美| 国产欧美日韩不卡| 欧美视频三区在线播放| 国产成人自拍在线| 亚洲一区二区三区四区在线观看| 精品少妇一区二区三区视频免付费 | 日韩国产欧美一区二区三区| 国产清纯白嫩初高生在线观看91 | 国产日韩欧美不卡在线| 欧美老女人第四色| 成人国产精品免费观看| 日韩va亚洲va欧美va久久| 中文字幕人成不卡一区| 日韩精品中文字幕一区| 在线观看国产精品网站| 国产风韵犹存在线视精品| 日韩国产欧美在线视频| 亚洲日本乱码在线观看| 国产亚洲欧美日韩日本| 337p亚洲精品色噜噜噜| 91黄色免费观看| 成人av影视在线观看|