/* * 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 */ package net.taler.lib.crypto 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() ) } }