????3??B??????????????A???????????????????????ù????N??E???????

??????????????N??E??????PublicKey?????£?

/**
     * ??????n??e??????
     * @param modulus   ???n??
     * @param publicExponent  ???e??
     * @return ??????PublicKey
     * @throws Exception
     */
    public static PublicKey getPublickKey(String modulus?? String publicExponent)
            throws Exception {
        KeySpec publicKeySpec = new RSAPublicKeySpec(
                new BigInteger(modulus?? 16)?? new BigInteger(publicExponent?? 16));
        KeyFactory factory = KeyFactory.getInstance("RSA");
        PublicKey publicKey = factory.generatePublic(publicKeySpec);
        return publicKey;
    }


??????????PublicKey????????????????????£?

/**
     * ?ù???????????
     * @param message  ??????????
     * @param cipherText  ???
     * @param pubKeyn ???n??
     * @param pubKeye ???e??
     * @return boolean ???????true??????false
     * @throws Exception
     */
    public static boolean verify(String message?? String cipherText??String pubKeyn??
            String pubKeye) throws Exception {
        Cipher c4 = Cipher.getInstance("RSA/ECB/PKCS1Padding");
        // ???????????Cipher??????г??????DECRYPT_MODE?????????
        c4.init(Cipher.DECRYPT_MODE?? getPublickKey(pubKeyn??pubKeye));
        // ????
        byte[] desDecTextBytes = c4.doFinal(Base64.base64ToByteArray(cipherText));
        // ????????????е?MD5
        String md5Digest1 = Base64.byteArrayToBase64(desDecTextBytes);
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        md5.update(message.getBytes("utf-8"));
        byte[] digestBytes = md5.digest();
        // ?????????????е?MD5
        String md5Digest2 = Base64.byteArrayToBase64(digestBytes);
        // ??????
        if (md5Digest1.equals(md5Digest2)) {
            return true;
        } else {
            return false;
        }
    }


?????????????????????

????4?????????.cer????????????????

/**
     * ??????cer
     * @param path .cer?????·??  ?磺c:/abc.cer
     * @return  base64???????
     * @throws IOException
     * @throws CertificateException
     */
    public static String getPublicKey(String path) throws IOException??
    CertificateException{
        InputStream inStream = new FileInputStream(path);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        int ch;
        String res = "";
        while ((ch = inStream.read()) != -1) {
            out.write(ch);
        }
        byte[] result = out.toByteArray();
        res = Base64.byteArrayToBase64(result);
        return res;
    }