use of org.xwiki.crypto.cipher.Cipher in project xwiki-commons by xwiki.
the class BcRc2CbcPaddedCipherFactoryTest method testRC2EffectiveBitsDecription.
@Test
public void testRC2EffectiveBitsDecription() throws Exception {
Cipher cipher27Enc = factory.getInstance(true, new KeyWithIVParameters(new RC2KeyParameters(KEY32, 27), IV8));
Cipher cipher27 = factory.getInstance(false, new KeyWithIVParameters(new RC2KeyParameters(KEY32, 27), IV8));
byte[] result = cipher27.doFinal(cipher27Enc.doFinal(BYTES));
assertThat(result.length, equalTo(BYTES.length));
assertThat(result, equalTo(BYTES));
result = cipher27.doFinal(cipher27Enc.doFinal(ANOTHER_BYTES));
assertThat(result.length, equalTo(ANOTHER_BYTES.length));
assertThat(result, equalTo(ANOTHER_BYTES));
}
use of org.xwiki.crypto.cipher.Cipher in project xwiki-commons by xwiki.
the class BcRsaOaepCipherFactoryTest method testRSAEncryptionDecryptionOneShot.
@Test
public void testRSAEncryptionDecryptionOneShot() throws Exception {
Cipher cipher = factory.getInstance(true, publicKey);
byte[] encrypted = cipher.doFinal(input);
cipher = factory.getInstance(false, privateKey);
assertThat(cipher.doFinal(encrypted), equalTo(input));
cipher = factory.getInstance(true, privateKey);
encrypted = cipher.doFinal(input);
cipher = factory.getInstance(false, publicKey);
assertThat(cipher.doFinal(encrypted), equalTo(input));
}
use of org.xwiki.crypto.cipher.Cipher in project xwiki-commons by xwiki.
the class BcRc2CbcPaddedCipherFactoryTest method testRC2EffectiveBitsEncription.
@Test
public void testRC2EffectiveBitsEncription() throws Exception {
Cipher cipher27 = factory.getInstance(true, new KeyWithIVParameters(new RC2KeyParameters(KEY32, 27), IV8));
byte[] result = cipher27.doFinal(BYTES);
assertThat(result.length, equalTo(BYTES_ENCRYPTED_SIZE));
assertThat(result, not(equalTo(getEncrypted())));
result = cipher27.doFinal(ANOTHER_BYTES);
assertThat(result.length, equalTo(ANOTHER_BYTES_ENCRYPTED_SIZE));
assertThat(result, not(equalTo(getAnotherEncrypted())));
}
Aggregations