Skip to content

Commit

Permalink
refactor(AES.kt): change ivData generation from sha256 to md5 (#507)
Browse files Browse the repository at this point in the history
refactor(SHA256.kt): change function name from sha1Data to sha256Data, to match the actual hash function used
  • Loading branch information
devkanro authored Apr 23, 2023
1 parent ba7d707 commit f8d72b4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import javax.crypto.spec.SecretKeySpec

fun ByteArray.aesEncrypt(key: String, from: Int = 0, to: Int = this.size): ByteArray {
val keyData = key.toByteArray().sha256()
val ivData = keyData.sha256()
val ivData = keyData.md5()
return this.aesEncrypt(keyData, ivData, from, to)
}

Expand All @@ -20,7 +20,7 @@ fun ByteArray.aesEncrypt(key: ByteArray, iv: ByteArray, from: Int = 0, to: Int =

fun ByteArray.aesDecrypt(key: String, from: Int = 0, to: Int = this.size): ByteArray {
val keyData = key.toByteArray().sha256()
val ivData = keyData.sha256()
val ivData = keyData.md5()
return this.aesDecrypt(keyData, ivData, from, to)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import java.security.MessageDigest
* Calculate SHA-256 of string, and convert it to hex string.
*/
fun String.sha256(): String {
return this.sha1Data().hex()
return this.sha256Data().hex()
}

/**
Expand Down

0 comments on commit f8d72b4

Please sign in to comment.