@Test void encrypt() throws NoSuchAlgorithmException, InvalidKeySpecException { bigIntModulus = new BigInteger("8a3706d24b5f0f0fe96afe4b6180d851bf892612b86a0bd5fe54b3ec6c0151a2307e1e2a21c7bbae0fec5ca317c1e81bdc28abcf776fd62c385594ec6c2859569735591bbac268fdfc7bbee37600e601526d9999b2696fead3d7f147c76dc15aa2c0fb6935478159687596bb546ab63c710f0a160e6d358aafa9027d6cddd303",16); bigIntPrivateExponent =new BigInteger("10001",16); palaintext = "{\"latitude\":\"39.921094\",\"loginName\":\"13241847378\",\"deviceId\":\"fd40d837-7a47-340d-8047-d7882d47ff7f\",\"versionCode\":362,\"loginPwd\":\"903198FC13E1963F30834F0AE04A1ACF\",\"longitude\":\"116.419445 \",\"loginKind\":\"normal\"}"; cryptograph = "JC8dE6A/GaHt48dkk5QcpFPBh4sgW913s4CFjZIb/0RShdoHgNPHK22Ove11yES4/TE/d+jQXqApGEV4BKr9DsOC4MkOc1+BuUUQyXmzHvU5NQMHVN5U4EH++idWCJZqSU1IdV0cph5+kY4zX0+523Jh0TrzPnA1HeN7ilg3Xw9IWpa8Z/6nKA/yast DZz3tUzMhcDQvxsonN+Yfb/bIdMJxMvi0KKTnXjvAuISaehv49Ti5n1fv6M2O2awVz+6CMjY8OHn9mxhuivVQpryyK3Bj30VfYqSRtbTYNF0PI4OFUDFI6RFJWJD4G9OqCu8mHdhQYLEgYhH93ttnl2xDfQ=="; RSAPublicKeySpec keySpec = new RSAPublicKeySpec(bigIntModulus,bigIntPrivateExponent); KeyFactory keyFactory = KeyFactory.getInstance("RSA"); RSAPublicKey rsaPublicKey = (RSAPublicKey) keyFactory.generatePublic(keySpec); byte[] result = null; result = RSAencryptionUtil.getInstance().encrypt("13241847378".getBytes(),rsaPublicKey); log.info("result 's value : {}", Base64.encodeToString(result)); result = RSAencryptionUtil.getInstance().encrypt(palaintext.getBytes(),rsaPublicKey); log.info("result 's value : {}", Base64.encodeToString(result)); }
public byte[] encrypt(byte[] data, RSAPublicKey publicKey){ return BasicEncryptionUtil.getInstance().encrypt(HelperHolder.ALGOROTHM_KEY,publicKey,data); }
RSAencryptionUtil { public byte[] encrypt(byte[] data, RSAPublicKey publicKey){ return BasicEncryptionUtil.getInstance().encrypt(HelperHolder.ALGOROTHM_KEY,publicKey,data); } }
RSAencryptionUtil { public byte[] encrypt(byte[] data, RSAPublicKey publicKey){ return BasicEncryptionUtil.getInstance().encrypt(HelperHolder.ALGOROTHM_KEY,publicKey,data); } private  RSAencryptionUtil(); }
RSAencryptionUtil { public byte[] encrypt(byte[] data, RSAPublicKey publicKey){ return BasicEncryptionUtil.getInstance().encrypt(HelperHolder.ALGOROTHM_KEY,publicKey,data); } 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 byte[] encrypt(byte[] data, RSAPublicKey publicKey){ return BasicEncryptionUtil.getInstance().encrypt(HelperHolder.ALGOROTHM_KEY,publicKey,data); } 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);  }