@@ -34,19 +34,29 @@ If you are looking for `SecureRandom`, see the [secure-random repo][url-secure-r
34
34
### Usage
35
35
36
36
``` kotlin
37
-
38
37
fun main () {
39
- val (random, key) = Random .Default .let { r -> Pair (r.nextBytes(615 ), r.nextBytes(50 )) }
38
+ // NOTE: SecureRandom is not included as a dependency in
39
+ // MACs, only using it here as an example b/c one
40
+ // should never derive a key using Random.
41
+ val key = SecureRandom ().nextBytesOf(100 )
42
+ val random = Random .Default .nextBytes(615 )
40
43
41
44
HmacMD5 (key).apply { update(random) }.doFinal()
42
45
43
46
HmacSHA1 (key).doFinal(random)
47
+ }
48
+ ```
49
+
50
+ ` SHA-2 `
51
+ ``` kotlin
52
+ fun main () {
53
+ val key = SecureRandom ().nextBytesOf(100 )
54
+ val random = Random .Default .nextBytes(615 )
44
55
45
- // SHA2
46
56
HmacSHA224 (key).doFinal(random)
47
57
48
58
HmacSHA256 (key).apply { update(random) }.doFinal(random)
49
-
59
+
50
60
HmacSha384 (key).doFinal(random)
51
61
52
62
val hMacSha512 = HmacSHA512 (key)
@@ -67,8 +77,23 @@ fun main() {
67
77
}
68
78
```
69
79
70
- ### Get Started
80
+ ` SHA-3 `
81
+ ``` kotlin
82
+ fun main () {
83
+ val key = SecureRandom ().nextBytesOf(100 )
84
+
85
+ HmacKeccak224 (key)
86
+ HmacKeccak256 (key)
87
+ HmacKeccak384 (key)
88
+ HmacKeccak512 (key)
89
+ HmacSHA3_224 (key)
90
+ HmacSHA3_256 (key)
91
+ HmacSHA3_384 (key)
92
+ HmacSHA3_512 (key)
93
+ }
94
+ ```
71
95
96
+ ### Get Started
72
97
73
98
The best way to keep ` KotlinCrypto ` dependencies up to date is by using the
74
99
[ version-catalog] [ url-version-catalog ] . Alternatively, you can use the BOM as
@@ -80,7 +105,7 @@ shown below.
80
105
// build.gradle.kts
81
106
dependencies {
82
107
// define the BOM and its version
83
- implementation(platform(" org.kotlincrypto.macs:bom:0.2.1 " ))
108
+ implementation(platform(" org.kotlincrypto.macs:bom:0.2.3 " ))
84
109
85
110
// define artifacts without version
86
111
@@ -92,17 +117,21 @@ dependencies {
92
117
93
118
// HmacSHA224, HmacSHA256, HmacSHA384, HmacSHA512, HmacSHA512/224, HmacSHA512/256
94
119
implementation(" org.kotlincrypto.macs:hmac-sha2" )
120
+
121
+ // HmacKeccak224, HmacKeccak256, HmacKeccak384, HmacKeccak512
122
+ // HmacSHA3-224, HmacSHA3-256, HmacSHA3-384, HmacSHA3-512
123
+ implementation(" org.kotlincrypto.macs:hmac-sha3" )
95
124
}
96
125
```
97
126
98
127
<!-- TAG_VERSION -->
99
- [ badge-latest-release ] : https://img.shields.io/badge/latest--release-0.2.1 -blue.svg?style=flat
128
+ [ badge-latest-release ] : https://img.shields.io/badge/latest--release-0.2.3 -blue.svg?style=flat
100
129
[ badge-license ] : https://img.shields.io/badge/license-Apache%20License%202.0-blue.svg?style=flat
101
130
102
131
<!-- TAG_DEPENDENCIES -->
103
132
[ badge-kotlin ] : https://img.shields.io/badge/kotlin-1.8.10-blue.svg?logo=kotlin
104
- [ badge-core ] : https://img.shields.io/badge/kotlincrypto.core-0.2.0 -blue.svg
105
- [ badge-hash ] : https://img.shields.io/badge/kotlincrypto.hash-0.2.1 -blue.svg
133
+ [ badge-core ] : https://img.shields.io/badge/kotlincrypto.core-0.2.3 -blue.svg
134
+ [ badge-hash ] : https://img.shields.io/badge/kotlincrypto.hash-0.2.3 -blue.svg
106
135
107
136
<!-- TAG_PLATFORMS -->
108
137
[ badge-platform-android ] : http://img.shields.io/badge/-android-6EDB8D.svg?style=flat
0 commit comments