RSAUtils { public static byte[] encryptByPublicKey(byte[] data, RSAPublicKey publicKey) { try { Cipher cipher = Cipher.getInstance(KEY_ALGORITHM_PADDING); cipher.init(Cipher.ENCRYPT_MODE, publicKey); int key_len = publicKey.getModulus().bitLength() / 8; return doFinal(cipher, data, key_len - 11); } catch (Exception e) { LOGGER.error("encryptByPublicKey ex", e); throw new CryptoException("RSA encrypt ex", e); } }  static Pair<RSAPublicKey, RSAPrivateKey> genKeyPair(int rsaKeySize); static String encodeBase64(Key key); static PrivateKey decodePrivateKey(String key); static PublicKey decodePublicKey(String publicKey); static String sign(byte[] data, String privateKey); static boolean verify(byte[] data, String publicKey, String sign); static RSAPublicKey getPublicKey(String modulus, String exponent); static RSAPrivateKey getPrivateKey(String modulus, String exponent); static byte[] encryptByPublicKey(byte[] data, RSAPublicKey publicKey); static byte[] decryptByPrivateKey(byte[] data, RSAPrivateKey privateKey); static byte[] decryptByPrivateKey(byte[] data, String privateKey); static byte[] decryptByPublicKey(byte[] data, String publicKey); static byte[] encryptByPublicKey(byte[] data, String publicKey); static byte[] encryptByPrivateKey(byte[] data, String privateKey); static void main(String[] args); static final int RAS_KEY_SIZE; static final String KEY_ALGORITHM; static final String KEY_ALGORITHM_PADDING; static final String SIGNATURE_ALGORITHM; }
@Test public void testEncryptByPublicKey() throws Exception { }