@Override public String encrypt(String value) { try { Cipher cipher = Cipher.getInstance(RSA_ECB_PKCS1_PADDING); cipher.init(Cipher.ENCRYPT_MODE, publicKey); return Base64.encodeToString(cipher.doFinal(ByteUtils.toBytes(value)), false); } catch (Exception e) { throw new RuntimeException(e); } }
@Override public String decrypt(String value) { try { Cipher cipher = Cipher.getInstance(RSA_ECB_PKCS1_PADDING); cipher.init(Cipher.DECRYPT_MODE, privateKey); return ByteUtils.toString(cipher.doFinal(Base64.decode(value))); } catch (Exception e) { throw new RuntimeException(e); } }