@Test public void testOfEncryptingAndDecryptingLongText() throws Exception { KeyPair pair = KeyGenerators.generateKeyPair("RSA", KeyGenerators.DEFAULT_KEYSIZE); StandardAsymmetricEncryptor enc = new StandardAsymmetricEncryptor(); String encrypted = enc.encrypt(LONG_TEXT, pair.getPublic()); String decrypted = enc.decrypt(encrypted, pair.getPrivate()); assertEquals(LONG_TEXT, decrypted); }
@Test public void testOfEncryptingAndDecryptingLongTextUsingStoredKey() throws Exception { KeyPair pair = KeyGenerators.generateKeyPair("RSA", KeyGenerators.DEFAULT_KEYSIZE); StandardAsymmetricEncryptor enc = new StandardAsymmetricEncryptor(); byte[] encoded = pair.getPrivate().getEncoded(); KeySpec spec = KeyGenerators.getPkcs8EncodedKeySpec(encoded); String encrypted = enc.encrypt(LONG_TEXT, pair.getPublic()); String decrypted = enc.decrypt(encrypted, KeyGenerators.generatePrivate("RSA", spec)); assertEquals(LONG_TEXT, decrypted); }