Yet Another OTP generator
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

HmacTest.kt 1.2KB

123456789101112131415161718192021222324252627282930313233343536
  1. package com.chameth.yaotp.algos
  2. import com.natpryce.hamkrest.assertion.assert
  3. import com.natpryce.hamkrest.equalTo
  4. import org.junit.Test
  5. class HmacTest {
  6. @Test
  7. fun testHmacSha1_withKnownValues() {
  8. val key = "key".toByteArray()
  9. val input = "The quick brown fox jumps over the lazy dog".toByteArray()
  10. val expected = "de7c9b85b8b78aa6bc8a7a36f70a90701c9db4d9"
  11. assert.that(hmacSha1(key, input).toHexString(), equalTo(expected))
  12. }
  13. @Test
  14. fun testHmacSha256_withKnownValues() {
  15. val key = "key".toByteArray()
  16. val input = "The quick brown fox jumps over the lazy dog".toByteArray()
  17. val expected = "f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8"
  18. assert.that(hmacSha256(key, input).toHexString(), equalTo(expected))
  19. }
  20. @Test
  21. fun testHmacSha512_withKnownValues() {
  22. val key = "key".toByteArray()
  23. val input = "The quick brown fox jumps over the lazy dog".toByteArray()
  24. val expected = "b42af09057bac1e2d41708e48a902e09b5ff7f12ab428a4fe86653c73dd248fb82f948a549f7b791a5b41915ee4d1ec3935357e4e2317250d0372afa2ebeeb3a"
  25. assert.that(hmacSha512(key, input).toHexString(), equalTo(expected))
  26. }
  27. }