blob: 3209e05144e884e0678d68cfdc3c6c63789b15bb (
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
|
/*
* This file is part of GNU Taler
* (C) 2020 Taler Systems S.A.
*
* GNU Taler is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; either version 3, or (at your option) any later version.
*
* GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
package net.taler.wallet.kotlin.crypto
import net.taler.wallet.kotlin.Base32Crockford
import kotlin.test.Test
import kotlin.test.assertEquals
@kotlin.ExperimentalStdlibApi
class Sha256Test {
private val crypto = CryptoFactory.getCrypto()
@Test
fun testAbc() {
assertEquals(
"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad",
crypto.sha256("abc".encodeToByteArray()).toHexString()
)
}
@Test
fun testEmptyString() {
assertEquals(
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
crypto.sha256("".encodeToByteArray()).toHexString()
)
}
@Test
fun testAbc448bits() {
assertEquals(
"248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1",
crypto.sha256("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq".encodeToByteArray()).toHexString()
)
}
@Test
fun testAbc896bits() {
assertEquals(
"cf5b16a778af8380036ce59e7b0492370b249b11e8f07a51afac45037afee9d1",
crypto.sha256("abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu".encodeToByteArray())
.toHexString()
)
}
@Test
fun testAMillionAs() {
val input = ByteArray(1_000_000) { 0x61 }
assertEquals(
"cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0",
crypto.sha256(input).toHexString()
)
}
}
|