?? asymmetryencrypt.java
字號:
package com.gmc.crypto;
import java.io.File;
import java.io.InputStream;
import java.security.Key;
import java.security.KeyPair;
import com.gmc.encrypt.Encryption;
/**
* 非對稱加密算法的上層接口,提供加/解密、數(shù)字簽名/驗證操作所需的方法
* 加密/解密操作(公鑰加密,私鑰解密)
* 數(shù)字簽名/驗證(私鑰加密,公鑰驗證)
* @author wanna
*
*/
public interface AsymmetryEncrypt extends Encryption
{
/**
* 加密文件
* @param file 待加密文件
* @param key 加密所需公鑰
* @return 存有密文信息的文件,擴展名為.fjm,路徑與file相同
* 例: 明文 :F:\1.txt
* 密文 :F:\1.txt.fjm
* @throws Exception
*/
public File encrypt(File file, Key key) throws Exception;
/**
* 加密 ,對輸入流中的數(shù)據(jù)進行加密,加密后將密文信息存儲在指定路徑cipherPath的文件中
* @param plainText 輸入流
* @param key 加密所需的公鑰
* @param cipherPath 指定的存儲密文信息的文件路徑
* @return 指定路徑下,存儲密文信息的文件
* @throws Exception
*/
public File encrypt(InputStream plainText, Key key,String cipherPath) throws Exception;
/**
* 解密
* @param cipherText 存有密文件信息的字節(jié)數(shù)組
* @param key 解密所需的私鑰
* @return 解密后的明文字符串
* @throws Exception
*/
public String decrypt(byte[] cipherText, Key key) throws Exception;
/**
* 對字符串進行解密操作
* @param cipherText 密文字符串
* @param key 解密所需的私鑰
* @return 明文字符串
* @throws Exception
*/
public String decrypt(String cipherText, Key key) throws Exception;
/**
* 解密,對擴展名為.fjm的密文文件進行解密
* @param cipherFile 存有密文信息的文件擴展名為.fjm
* @param key 解密所需的私鑰
* @return 存有明文信息的文件
* 例 :cipherFile 為 F:\1.txt.fjm
* 解密后 F:\1.txt 存放明文信息
* @throws Exception
*/
public File decrypt(File cipherFile, Key key) throws Exception;
/**
* 解密 ,對文件流進行解密操作
* @param cipherText 存有密文信息的輸入流
* @param key 解密所需的私鑰
* @param plainPath 存放明文信息文件的指定路徑
* @return 指定路徑下,存放明文信息的文件
* @throws Exception
*/
public File decrypt(InputStream cipherText, Key key,String plainPath) throws Exception;
/**
* 數(shù)字簽名
* @param plainText 明文字符串
* @param key 簽名所需的私鑰
* @return 簽名后的信息字符串
* @throws Exception
*/
public String digitalSignature(String plainText, Key key) throws Exception;
/**
* 簽名驗證
* @param plainText 明文字符串
* @param signMessage 簽名信息
* @param key 簽名驗證的公鑰
* @return 驗證結(jié)果
* true 簽名正確
* false 簽名錯誤
* @throws Exception
*/
public boolean validateSignature(String plainText, String signMessage, Key key) throws Exception;
/**
* 數(shù)字簽名
* @param file 待簽名文件
* @param key 簽名所需的私鑰
* @return 存有簽名信息的文件,擴展名為.sig
* 例 file F:\1.txt
* 簽名信息文件 F:\1.txt.sig
*
* @throws Exception
*/
public File digitalSignature(File file, Key key) throws Exception;
/**
* 簽名驗證
* @param plainText 明文
* @param signMessage 在有簽名信息的文件,擴展名為.sig
* @param key 簽名驗證所需公鑰
* @return 驗證結(jié)果
* true 簽名正確
* false 簽名錯誤
* @throws Exception
*/
public boolean validateSignature(File plainText, File signMessage, Key key) throws Exception;
/**
* 數(shù)字簽名
* @param plainStream 要進行數(shù)字簽名的數(shù)據(jù)流
* @param key 數(shù)字簽名所需的私鑰
* @param signPath 簽名后,存放簽名信息的文件路徑
* @return 存有簽名信息的文件
* @throws Exception
*/
public File digitalSignature(InputStream plainStream, Key key,String signPath) throws Exception;
/**
* 簽名驗證
* @param plainStream 存有明文信息的輸入流
* @param signStream 存有簽名信息的輸入流
* @param key 簽名驗證所需的公鑰
* @return
* @throws Exception
*/
public boolean validateSignature(InputStream plainStream, InputStream signStream, Key key) throws Exception;
/**
* 獲得公鑰
* @return
* @throws Exception
*/
public Key getPublicKey() throws Exception;
/**
* 獲得私鑰
* @return
* @throws Exception
*/
public Key getPrivateKey() throws Exception;
/**
* 獲得加密算法的密鑰對
* @return
* @throws Exception
*/
public KeyPair getKeyPair() throws Exception;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -