@Test void getPublicKey() throws Exception { X509EncodedKeySpec keySpec = new X509EncodedKeySpec(Base64.decode("MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCKNwbSS18PD+lq/kthgNhRv4kmErhqC9X+VLPsbAFRojB+Hiohx7uuD+xcoxfB6BvcKKvPd2/WLDhVlOxsKFlWlzVZG7rCaP38e77jdgDmAVJtmZmyaW/q09fxR8dtwVqiwPtpNUeBWWh1lrtUarY8cQ8KFg5tNYqvqQJ9bN3TAwIDAQAB")); RSAPublicKey publicKey = (RSAPublicKey) KeyFactory.getInstance("RSA").generatePublic(keySpec); Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding"); cipher.init(Cipher.ENCRYPT_MODE,publicKey); byte[] result = cipher.doFinal(new BigInteger("7B7D",16).toByteArray()); System.out.println(Base64.encodeToString(result)); String cryptograph = "PyTBokP3d9gnntWM\\/iXiDbGvSDcMjqkDZcP6YrQBzrzwCUQfOVHSlt8NHd3NEdnEFsZEBVlHwznh2vfEs5AWT9qxNiTkRgEACP5QpJQPq51htp\\/kG\\/LHKHlGf21Onra80P0gyQ+AYbqMunQOCpf2mh0pbSyw2DGy5nf5iGLzOCw="; RSAPrivateKey privateKey = (RSAPrivateKey) KeyFactory.getInstance("RSA").generatePrivate(keySpec); cipher.init(Cipher.DECRYPT_MODE,privateKey); result = cipher.doFinal(Base64.decode(cryptograph)); System.out.println(Base64.encodeToString(result)); }
public RSAPublicKey getpublicKey(Map<String, Object> keyMap){ RSAPublicKey publicKey = (RSAPublicKey) keyMap.get(HelperHolder.PUBLIC_KEY); return publicKey; }
RSAencryptionUtil { public RSAPublicKey getpublicKey(Map<String, Object> keyMap){ RSAPublicKey publicKey = (RSAPublicKey) keyMap.get(HelperHolder.PUBLIC_KEY); return publicKey; } }
RSAencryptionUtil { public RSAPublicKey getpublicKey(Map<String, Object> keyMap){ RSAPublicKey publicKey = (RSAPublicKey) keyMap.get(HelperHolder.PUBLIC_KEY); return publicKey; } private  RSAencryptionUtil(); }
RSAencryptionUtil { public RSAPublicKey getpublicKey(Map<String, Object> keyMap){ RSAPublicKey publicKey = (RSAPublicKey) keyMap.get(HelperHolder.PUBLIC_KEY); return publicKey; } private  RSAencryptionUtil(); static RSAencryptionUtil getInstance(); Map<String, Object> initKey(); RSAPublicKey getpublicKey(Map<String, Object> keyMap); RSAPrivateKey getPrivateKey(Map<String, Object> keyMap); byte[] encrypt(byte[] data, RSAPublicKey publicKey); byte[] decrypt(byte[] data, RSAPrivateKey privateKey); }
RSAencryptionUtil { public RSAPublicKey getpublicKey(Map<String, Object> keyMap){ RSAPublicKey publicKey = (RSAPublicKey) keyMap.get(HelperHolder.PUBLIC_KEY); return publicKey; } private  RSAencryptionUtil(); static RSAencryptionUtil getInstance(); Map<String, Object> initKey(); RSAPublicKey getpublicKey(Map<String, Object> keyMap); RSAPrivateKey getPrivateKey(Map<String, Object> keyMap); byte[] encrypt(byte[] data, RSAPublicKey publicKey); byte[] decrypt(byte[] data, RSAPrivateKey privateKey);  }