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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? sign.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.math.BigInteger;

import java.security.InvalidKeyException;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.Signature;
import java.security.SignatureException;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.KeySpec;
import java.security.spec.RSAPrivateKeySpec;
import java.security.spec.RSAPublicKeySpec;

import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.ShortBufferException;

import org.bsmith.encoding.Base16;


/**
 * the RSA-SHA1 signature class with PKCS#1 v1.5 padding.
 */
public class Sign
{
    public static void dump(String label, byte[] data)
    {
        String hex_str = Base16.encode(data);
        System.out.println(label+"="+hex_str);
    }
    
    /**
     * the example.
     * @param args
     * @throws UnsupportedEncodingException
     * @throws NoSuchAlgorithmException
     * @throws NoSuchPaddingException
     * @throws InvalidKeySpecException
     * @throws ShortBufferException
     * @throws IllegalBlockSizeException
     * @throws BadPaddingException
     * @throws InvalidKeyException
     * @throws SignatureException
     */
    public static void main(String[] args) throws UnsupportedEncodingException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeySpecException, ShortBufferException, IllegalBlockSizeException, BadPaddingException, InvalidKeyException, SignatureException
    {
        System.out.println("=======================RSA-SHA1 Sign=====================");
    
        String N = "90755611487566208138950675092879865387596685014726501531250157258482495478524769456222913843665634824684037468817980814231054856125127115894189385717148934026931120932481402379431731629550862846041784305274651476086892165805223719552575599962253392248079811268061946102234935422772131475340988882825043233323";
        String e ="65537";
        String d = "17790520481266507102264359414044396762660094486842415203197747383916331528947124726552875080482359744765793816651732601742929364124685415229452844016482477236658413327331659722342187036963943428678684677279032263501011143882814728160215380051287503219732737197808611144507720521201393129692996926599975297921";
        
        String msg = "bsmith am a good guy.";
        byte[] indata = msg.getBytes("UTF-8");
        {
            String hex_str = Base16.encode(indata);
            System.out.println(hex_str);
        }
        
        Sign ser = new Sign();
        ser.initPrivateKey(N, e, d);
        
        byte[] outdata = ser.sign(indata, 0, indata.length);
        dump("outdata", outdata);
        
        byte[] outdata1 = new byte[ser.getCipherLen()];
        ser.sign(indata, 0, indata.length, outdata1, 0);
        dump("outdata1", outdata1);
        
        Sign ver = new Sign();
        ver.initPublicKey(N, e);
        System.out.println(String.format("result <?> true : %s", ver.verify(indata, outdata)));
        System.out.println(String.format("result <?> true : %s", ver.verify(indata, outdata1)));
        
        byte[] indata1 = "bsmith is not a good guy.".getBytes("UTF-8");
        System.out.println(String.format("result <?> false : %s", ver.verify(indata1, outdata)));
    }

    private Signature ser;  // signer.
    private PrivateKey sk;  // private key for signer.
    private Signature ver;  // verifier
    private PublicKey pk;   // public key for verifier.
    private int KEY_BYTE_LEN;   // the RSA key bytes length.

    public Sign()
    {
    }
    
    /**
     * init public key for verifier.
     * @param N N factor in RSA, aslo called modulus.
     * @param e e factor in RSA, aslo called publicExponent.
     * @throws NoSuchAlgorithmException
     * @throws NoSuchPaddingException
     * @throws InvalidKeySpecException
     */
    public void initPublicKey(String N, String e) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeySpecException
    {
        KeyFactory keyFactory = KeyFactory.getInstance("RSA");
        BigInteger big_N = new BigInteger(N);
        KEY_BYTE_LEN = (big_N.bitLength())>>3;
        BigInteger big_e = new BigInteger(e);
        KeySpec keySpec = new RSAPublicKeySpec(big_N, big_e);
        pk = keyFactory.generatePublic(keySpec);
    }
    
    /**
     * init private key for signer.
     * @param N N factor in RSA, aslo called modulus.
     * @param e e factor in RSA, aslo called publicExponent, ignored, just keep compatible with C++ interface.
     * @param d d factor in RSA, aslo called privateExponent.
     * @throws NoSuchAlgorithmException
     * @throws NoSuchPaddingException
     * @throws InvalidKeySpecException
     */
    public void initPrivateKey(String N, String e, String d) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeySpecException
    {
        KeyFactory keyFactory = KeyFactory.getInstance("RSA");
        BigInteger big_N = new BigInteger(N);
        KEY_BYTE_LEN = (big_N.bitLength())>>3;
        BigInteger big_d = new BigInteger(d);
        KeySpec keySpec = new RSAPrivateKeySpec(big_N, big_d);
        sk = keyFactory.generatePrivate(keySpec);
    }
    
    /**
     * get the signer length in bytes.
     * this value is fixed, and is equals the RSA key bytes length.
     * @return the signer length.
     */
    public int getCipherLen()
    {
        return KEY_BYTE_LEN;
    }
    
    /**
     * sign 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.
     * @return the actual output data length.
     * @throws NoSuchAlgorithmException
     * @throws InvalidKeyException
     * @throws SignatureException
     */
    public int sign(byte[] indata, int inoff, int inlen, byte[] outdata, int outoff) throws NoSuchAlgorithmException, InvalidKeyException, SignatureException
    {
        initSigner();
        ser.update(indata, inoff, inlen);
        return ser.sign(outdata, outoff, KEY_BYTE_LEN);
    }
    
    /**
     * sign 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 data.
     * @throws NoSuchAlgorithmException
     * @throws InvalidKeyException
     * @throws SignatureException
     */
    public byte[] sign(byte[] indata, int inoff, int inlen) throws NoSuchAlgorithmException, InvalidKeyException, SignatureException
    {
        initSigner();
        ser.update(indata, inoff, inlen);
        return ser.sign();
    }
    
    /**
     * sign the input data to output data.
     * @param indata the input data.
     * @return the output data.
     * @throws NoSuchAlgorithmException
     * @throws InvalidKeyException
     * @throws SignatureException
     */
    public byte[] sign(byte[] indata) throws NoSuchAlgorithmException, InvalidKeyException, SignatureException
    {
        initSigner();
        ser.update(indata);
        return ser.sign();
    }
    
    /**
     * verify the input data and the signer.
     * @param plaindata the input plain data.
     * @param plainoff the input plain data offset.
     * @param plainlen the input plain data length.
     * @param signdata the signer data.
     * @param signoff the signer data offset.
     * @param signlen the signer data length.
     * @return the verify result, true passed, false failed.
     * @throws NoSuchAlgorithmException
     * @throws InvalidKeyException
     * @throws SignatureException
     */
    public boolean verify(byte[] plaindata, int plainoff, int plainlen, byte[] signdata, int signoff, int signlen) throws NoSuchAlgorithmException, InvalidKeyException, SignatureException
    {
        initVerifier();
        ver.update(plaindata, plainoff, plainlen);
        return ver.verify(signdata, signoff, signlen);
    }
    
    /**
     * verify the input data and the signer.
     * @param plaindata the input plain data.
     * @param signdata the signer data.
     * @return the verify result, true passed, false failed.
     * @throws NoSuchAlgorithmException
     * @throws InvalidKeyException
     * @throws SignatureException
     */
    public boolean verify(byte[] plaindata, byte[] signdata) throws NoSuchAlgorithmException, InvalidKeyException, SignatureException
    {
        initVerifier();
        ver.update(plaindata);
        return ver.verify(signdata);
    }
    
    private void initSigner() throws NoSuchAlgorithmException, InvalidKeyException
    {
        if (null == ser)
        {
            ser = Signature.getInstance("SHA1withRSA");
            ser.initSign(sk);
        }
    }
    
    private void initVerifier() throws NoSuchAlgorithmException, InvalidKeyException
    {
        if (null == ver)
        {
            ver = Signature.getInstance("SHA1withRSA");
            ver.initVerify(pk);
        }
    }
}

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
中文字幕一区二区三区乱码在线 | 日韩理论片中文av| 日本韩国一区二区| 国产精品自拍三区| 亚洲特级片在线| 久久噜噜亚洲综合| 欧美人动与zoxxxx乱| 国产成人在线影院| 日韩av在线免费观看不卡| 亚洲免费色视频| 国产日产欧美一区| 日韩亚洲欧美高清| 欧美日韩国产一级| 91蝌蚪porny| 成人免费观看视频| 粗大黑人巨茎大战欧美成人| 亚洲福利电影网| 亚洲欧美日韩人成在线播放| 精品久久五月天| 精品久久久久久久久久久久久久久久久 | 26uuu国产在线精品一区二区| 色屁屁一区二区| 色视频成人在线观看免| 成人精品视频.| 岛国一区二区三区| 成人国产视频在线观看| 一本到高清视频免费精品| 国产美女av一区二区三区| 国内精品久久久久影院色| 午夜婷婷国产麻豆精品| 日精品一区二区| 美日韩黄色大片| 国产成人8x视频一区二区| 国产91综合一区在线观看| 成人福利电影精品一区二区在线观看| 免费欧美日韩国产三级电影| 精品中文字幕一区二区小辣椒| 久久国产精品无码网站| 国产乱人伦偷精品视频免下载| 成人综合在线网站| 欧美专区在线观看一区| 精品蜜桃在线看| 亚洲欧美日韩久久精品| 美女看a上一区| 91丨九色丨尤物| 日韩午夜激情免费电影| 国产日韩视频一区二区三区| 日韩精品一区二区三区swag| 国产精品色噜噜| 午夜成人在线视频| 99久久久国产精品| 精品久久久久久久久久久久包黑料| 欧美极品aⅴ影院| 久久精品国产在热久久| 97精品国产97久久久久久久久久久久 | 色婷婷综合久久久久中文| 国产婷婷色一区二区三区四区 | 秋霞电影网一区二区| 成人在线视频一区| 欧美精品在欧美一区二区少妇| 国产女人18毛片水真多成人如厕| 亚洲国产cao| 欧日韩精品视频| 亚洲精品欧美综合四区| 成人妖精视频yjsp地址| 日韩免费福利电影在线观看| 五月天亚洲婷婷| 欧美性受xxxx| 亚洲大片在线观看| 欧美一级二级三级蜜桃| 午夜久久久久久久久| 日韩午夜激情电影| 九九九精品视频| 欧美男同性恋视频网站| 在线成人午夜影院| 国产午夜亚洲精品午夜鲁丝片| 日韩激情av在线| 国产一区二区三区综合| 99国产精品视频免费观看| 日韩一区二区三区三四区视频在线观看 | 色综合天天做天天爱| 中文字幕色av一区二区三区| 国产成人在线色| 亚洲视频一区二区在线| 成人免费视频免费观看| 久久久一区二区| 成人污视频在线观看| 亚洲人成小说网站色在线| 色综合色狠狠综合色| 亚洲精品国久久99热| 国产乱码精品一区二区三 | 色999日韩国产欧美一区二区| 国产精品福利一区| www.久久精品| 国产精品久久久久三级| 99久久久精品| 午夜激情一区二区三区| 久久看人人爽人人| 99国产欧美久久久精品| 亚洲成人自拍一区| 国产亚洲欧美日韩在线一区| yourporn久久国产精品| 免费成人av在线播放| 91久久香蕉国产日韩欧美9色| 午夜精品一区二区三区电影天堂| 这里只有精品免费| 国产乱人伦偷精品视频不卡| 亚洲精品v日韩精品| 欧美精品久久99| 国产一区二区中文字幕| 中文字幕第一页久久| 日韩欧美一区二区不卡| 成人激情文学综合网| 午夜精品免费在线| 亚洲人成亚洲人成在线观看图片 | 日韩一区欧美二区| 国产精品免费免费| 91精品国产综合久久久蜜臀粉嫩 | 精品国内片67194| 色丁香久综合在线久综合在线观看| 亚洲国产wwwccc36天堂| 久久精品亚洲麻豆av一区二区 | 91影视在线播放| 国产精品中文有码| 午夜精品视频一区| 亚洲一区av在线| 中文字幕一区二区三区蜜月| 中文字幕日韩一区| 国产日产欧美一区| 国产蜜臀97一区二区三区 | 成人免费在线播放视频| 国产精品美女久久久久av爽李琼 | 国产美女视频一区| 国产成人av一区二区三区在线| 紧缚奴在线一区二区三区| 美女脱光内衣内裤视频久久网站| 日韩精品亚洲专区| 日韩电影一二三区| 日韩av一区二区三区| 久久综合久久综合久久| 久久久久99精品一区| 欧美一级视频精品观看| 欧美高清视频不卡网| 91精品国产综合久久久久久漫画 | av亚洲精华国产精华| 一本色道久久加勒比精品| 欧美午夜一区二区三区| eeuss鲁片一区二区三区在线观看| 成人精品高清在线| 欧美性受极品xxxx喷水| 欧美日韩一区二区三区高清| 在线播放中文字幕一区| 欧美日韩的一区二区| 久久久亚洲精品石原莉奈| 欧美国产成人精品| 亚洲成在人线在线播放| 成人免费毛片app| 91久久精品网| 国产亚洲欧美中文| 日韩激情一区二区| 国产69精品久久99不卡| 精品视频免费在线| 国产精品毛片a∨一区二区三区| 亚洲永久免费视频| 国产精品 日产精品 欧美精品| 色悠悠亚洲一区二区| 欧美xxxxxxxxx| 亚洲大片一区二区三区| 91浏览器在线视频| 国产女人aaa级久久久级| 亚洲成av人片观看| 欧美综合在线视频| 亚洲欧美综合另类在线卡通| 亚洲一区二区在线视频| 不卡高清视频专区| 国产欧美日韩另类一区| 久久国产精品免费| 欧美男同性恋视频网站| 中文字幕人成不卡一区| 国产精品小仙女| 欧美一级欧美一级在线播放| 一区二区三区视频在线观看| 成人性生交大片免费看中文| 欧美sm美女调教| 日本不卡一二三| 日韩一区二区三区观看| 日韩av一区二| 欧美成人精品1314www| 天堂久久一区二区三区| 欧美日韩在线亚洲一区蜜芽| 亚洲第一成年网| 欧美视频一区二| 国产精品一色哟哟哟| 国产欧美一区视频| 成人亚洲一区二区一| 国产精品色在线观看| av不卡在线播放| 日韩精品欧美成人高清一区二区| 日韩一区二区三| 不卡的av电影在线观看|