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.3KB

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