aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/de/thedevstack/conversationsplus/utils/SimpleCryptoUtilTest.java
blob: 7e71a3bf9757c1392e13291e6f3bd3ab80175d27 (plain)
1
2
3
4
5
6
7
8
9
10
11
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package de.thedevstack.conversationsplus.utils;

import org.junit.Test;

import static org.junit.Assert.assertEquals;

/**
 * Created by steckbrief on 10.07.2016.
 */
public class SimpleCryptoUtilTest {
    @Test
    public void testEncryptWithNullSeed() {
        String seed = null;
        String cleartext = "Test123";
        String expectedResult = null;
        String result = SimpleCryptoUtil.encrypt(seed, cleartext);
        assertEquals(expectedResult, result);
    }

    @Test
    public void testEncryptWithWhitespaceSeed() {
        String seed = " ";
        String cleartext = "Test123";
        String expectedResult = "3E7721EF6F8D9E47403AC03F45341E5C";
        String result = SimpleCryptoUtil.encrypt(seed, cleartext);
        assertEquals(expectedResult, result);
    }

    @Test
    public void testEncryptWithZeroLengthSeed() {
        String seed = "";
        String cleartext = "Test123";
        String expectedResult = "BEFF4A6800B91AE505672CA238D7C72F";
        String result = SimpleCryptoUtil.encrypt(seed, cleartext);
        assertEquals(expectedResult, result);
    }

    @Test
    public void testEncryptWithNullCleartext() {
        String seed = "asdasdadasd";
        String cleartext = null;
        String expectedResult = null;
        String result = SimpleCryptoUtil.encrypt(seed, cleartext);
        assertEquals(expectedResult, result);
    }

    @Test
    public void testEncryptWithWhitespaceCleartext() {
        String seed = "asdasdadasd";
        String cleartext = " ";
        String expectedResult = "1C476E5E4E66809AB6C91EEF9C93A32F";
        String result = SimpleCryptoUtil.encrypt(seed, cleartext);
        assertEquals(expectedResult, result);
    }

    @Test
    public void testEncryptWithZeroLengthCleartext() {
        String seed = "asdasdadasd";
        String cleartext = "";
        String expectedResult = "22BD1DA9232CA6594A466B419B2AFB8C";
        String result = SimpleCryptoUtil.encrypt(seed, cleartext);
        assertEquals(expectedResult, result);
    }

    @Test
    public void testEncrypt() {
        String seed = "asdasdadasd";
        String cleartext = "Test123";
        String expectedResult = "E1D9C96AAF09434D915A2F0C147CBF64";
        String result = SimpleCryptoUtil.encrypt(seed, cleartext);
        assertEquals(expectedResult, result);
    }

    @Test
    public void testDecryptWithNullSeed() {
        String seed = null;
        String encryptedText = "E1D9C96AAF09434D915A2F0C147CBF64";
        String expectedResult = null;
        String result = SimpleCryptoUtil.decrypt(seed, encryptedText);
        assertEquals(expectedResult, result);
    }

    @Test
    public void testDecryptWithWhitespaceSeed() {
        String seed = " ";
        String encryptedText = "3E7721EF6F8D9E47403AC03F45341E5C";
        String expectedResult = "Test123";
        String result = SimpleCryptoUtil.decrypt(seed, encryptedText);
        assertEquals(expectedResult, result);
    }

    @Test
    public void testDecryptWithZeroLengthSeed() {
        String seed = "";
        String encryptedText = "BEFF4A6800B91AE505672CA238D7C72F";
        String expectedResult = "Test123";
        String result = SimpleCryptoUtil.decrypt(seed, encryptedText);
        assertEquals(expectedResult, result);
    }

    @Test
    public void testDecryptWithNullEncryptedText() {
        String seed = "asdasdadasd";
        String encryptedText = null;
        String expectedResult = null;
        String result = SimpleCryptoUtil.decrypt(seed, encryptedText);
        assertEquals(expectedResult, result);
    }

    @Test
    public void testDecryptWithWhitespaceEncryptedText() {
        String seed = "asdasdadasd";
        String encryptedText = " ";
        String expectedResult = "";
        String result = SimpleCryptoUtil.decrypt(seed, encryptedText);
        assertEquals(expectedResult, result);
    }

    @Test
    public void testDecryptWithZeroLengthEncryptedText() {
        String seed = "asdasdadasd";
        String encryptedText = "";
        String expectedResult = "";
        String result = SimpleCryptoUtil.decrypt(seed, encryptedText);
        assertEquals(expectedResult, result);
    }

    @Test
    public void testDecrypt() {
        String seed = "asdasdadasd";
        String encryptedText = "E1D9C96AAF09434D915A2F0C147CBF64";
        String expectedResult = "Test123";
        String result = SimpleCryptoUtil.decrypt(seed, encryptedText);
        assertEquals(expectedResult, result);
    }
}