package com.dji.sample.droneairport.utils.SM2; import org.bouncycastle.crypto.InvalidCipherTextException; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.security.NoSuchAlgorithmException; import java.util.Map; public class Utils { /** * get key pair */ public static Map createKeyPair() throws NoSuchAlgorithmException { return SecretCommon.createKeyPair(); } /** * encrypt * @param plainText 需加密的明文字符串 * @param publicKey 公钥 */ public static String encrypt(String plainText, String publicKey) throws IOException, InvalidCipherTextException { return encrypt(plainText, publicKey, ModeTypeConstant.BASE); } /** * encrypt * @param plainText 需加密的明文字符串 * @param publicKey 公钥 * @param modeType base:标准;bc:BC模式 */ public static String encrypt(String plainText, String publicKey, String modeType) throws IOException, InvalidCipherTextException { return SecretCommon.encrypt(plainText, publicKey, ModeTypeConstant.getMode(modeType)); } /** * decrypt * @param cipherText 需加密的字符串 * @param privateKey 私钥 */ public static String decrypt(String cipherText, String privateKey) throws InvalidCipherTextException, UnsupportedEncodingException { return decrypt(cipherText, privateKey, ModeTypeConstant.BASE); } /** * decrypt * @param cipherText 需加密的字符串 * @param privateKey 私钥 * @param modeType base:标准;bc:BC模式 */ public static String decrypt(String cipherText, String privateKey, String modeType) throws InvalidCipherTextException, UnsupportedEncodingException { return SecretCommon.decrypt(cipherText, privateKey, ModeTypeConstant.getMode(modeType)); } }