コード例 #1
0
  @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);
  }
コード例 #2
0
  @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);
  }