Search in sources :

Example 6 with Cipher

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));
}
Also used : RC2KeyParameters(org.xwiki.crypto.params.cipher.symmetric.RC2KeyParameters) Cipher(org.xwiki.crypto.cipher.Cipher) KeyWithIVParameters(org.xwiki.crypto.params.cipher.symmetric.KeyWithIVParameters) Test(org.junit.Test)

Example 7 with Cipher

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));
}
Also used : Cipher(org.xwiki.crypto.cipher.Cipher) Test(org.junit.Test)

Example 8 with Cipher

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())));
}
Also used : RC2KeyParameters(org.xwiki.crypto.params.cipher.symmetric.RC2KeyParameters) Cipher(org.xwiki.crypto.cipher.Cipher) KeyWithIVParameters(org.xwiki.crypto.params.cipher.symmetric.KeyWithIVParameters) Test(org.junit.Test)

Aggregations

Cipher (org.xwiki.crypto.cipher.Cipher)8 Test (org.junit.Test)7 KeyWithIVParameters (org.xwiki.crypto.params.cipher.symmetric.KeyWithIVParameters)2 RC2KeyParameters (org.xwiki.crypto.params.cipher.symmetric.RC2KeyParameters)2