Java??RSA??????????????????
???????????? ???????[ 2012/9/7 11:44:36 ] ????????
?????????飺
????RSA??????????????????????CFCA??????????????????RSA????????????????????????????????????????????????????????????????????????????????????????????????????????????RSA??????????????????????????????????????????????е???????????
????????RSA???????????????????????????????????±?
??????????÷????
?????? ????A??B??????????????A?????????
?????? A????????????????????????????????????????????????B??
?????? B?????????????A????????????????????????????????δ???????
?????? B????????????????????????????????????????????A??????????м??????????????????????????????
?????? A???B?????????????????????????????????????ɡ?
????????????????
????1?????????????????????????
	/**
	     * ?????  ????PrivateKey
	     * @param path  ???????????·??
	     * @param password  ?????????
	     * @return ??????PrivateKey
	     * @throws KeyStoreException
	     * @throws NoSuchAlgorithmException
	     * @throws CertificateException
	     * @throws IOException
	     * @throws UnrecoverableKeyException
	     */
	    private static PrivateKey getPrivateKey(String path??String password)
	            throws KeyStoreException?? NoSuchAlgorithmException?? CertificateException??
	            IOException?? UnrecoverableKeyException {
	        KeyStore ks = KeyStore.getInstance("PKCS12");
	        FileInputStream fis = new FileInputStream(path);
	        char[] nPassword = null;
	        if ((password == null) || password.trim().equals("")) {
	            nPassword = null;
	        } else {
	            nPassword = password.toCharArray();
	        }
	        ks.load(fis?? nPassword);
	        fis.close();
	        Enumeration<String> en = ks.aliases();
	        String keyAlias = null;
	        if (en.hasMoreElements()) {
	            keyAlias = (String) en.nextElement();
	        }
	 
	        return (PrivateKey) ks.getKey(keyAlias?? nPassword);
	    }
	
	????2?????????????????????????????????????????????????′???
	/**
	     * ??????? ??????????£?BASE64(RSA(MD5(src)??privatekey))??????src????????????????
	privatekey???????CFCA???????
	     * @param plainText ??????????
	     * @param path ?????·??
	     * @param password  ?????????
	     * @return ???????????????
	     * @throws Exception
	     */
	    public static String sign(String plainText??String path??String password)
	            throws Exception  {
	        /*
	         * MD5????
	         */
	        MessageDigest md5 = MessageDigest.getInstance("MD5");
	        md5.update(plainText.getBytes("utf-8"));
	        byte[] digestBytes = md5.digest();
	        /*
	         * ??????????? RSA
	         * Cipher???????????????????????RSA
	         */
	        Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
	        //ENCRYPT_MODE??????????
	        cipher.init(Cipher.ENCRYPT_MODE?? getPrivateKey(path?? password));
	        //????
	        byte[] rsaBytes = cipher.doFinal(digestBytes);
	        //Base64????
	        return Base64.byteArrayToBase64(rsaBytes);
	
??????
					
					???·???
App??С????H5?????????????????Щ??
2024/9/11 15:34:34?????????????????????????
2024/9/10 11:13:49P-One ???????????????????????????????????????
2024/9/10 10:14:12???????????????????????????
2024/9/9 18:04:26??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44
					
			
								
								
								
								
								
								
								
								
								
								
				
sales@spasvo.com