BlowfishEncryptorTest.java 1.38 KB
Newer Older
1 2 3 4 5 6
package org.jivesoftware.util;

import java.util.UUID;

import org.junit.Test;

7 8 9 10 11
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;

public class BlowfishEncryptorTest {
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53

	@Test
	public void testEncryptionUsingDefaultKey() {
		String test = UUID.randomUUID().toString();
		
		Encryptor encryptor = new Blowfish();
		
		String b64Encrypted = encryptor.encrypt(test);
		assertFalse(test.equals(b64Encrypted));
		
		assertEquals(test, encryptor.decrypt(b64Encrypted));
	}

	@Test
	public void testEncryptionUsingCustomKey() {
		
		String test = UUID.randomUUID().toString();
		
		Encryptor encryptor = new Blowfish(UUID.randomUUID().toString());
		
		String b64Encrypted = encryptor.encrypt(test);
		assertFalse(test.equals(b64Encrypted));
		
		assertEquals(test, encryptor.decrypt(b64Encrypted));
	}

	@Test
	public void testEncryptionForEmptyString() {
		
		String test = "";
		
		Encryptor encryptor = new Blowfish();
		
		String b64Encrypted = encryptor.encrypt(test);
		assertFalse(test.equals(b64Encrypted));
		
		assertEquals(test, encryptor.decrypt(b64Encrypted));
	}


	@Test
	public void testEncryptionForNullString() {
54 55 56
        Encryptor encryptor = new Blowfish();

        String b64Encrypted = encryptor.encrypt(null);
57

58 59
        assertNull(b64Encrypted);
    }
60
}