Skip to content

Commit

Permalink
Change hash function
Browse files Browse the repository at this point in the history
  • Loading branch information
Utngy Pisal committed Sep 28, 2022
1 parent fe0b67a commit 649ea7f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions hybrid-crypto/src/main/java/me/pisal/hybridcrypto/aes/AESCipher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,20 @@ import javax.crypto.spec.PBEKeySpec
import javax.crypto.spec.SecretKeySpec

class AESCipher(
/**
* Recommended by OWASP: 16 (bytes)
*/
private val aesKeySizeInBytes: Int,

/**
* Recommended by OWASP: "AES/CBC/PKCS7Padding"
*/
private val aesMode: String = "AES/CBC/PKCS7Padding",

/**
* Recommended: 100 good an equilibrium between robustness and performance.
* The bigger, the more secure, but slower at the same time.
*/
private val keyIterationCount: Int = 100
) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import me.pisal.hybridcrypto.rsa.RSACipher
import java.io.Serializable
import java.security.MessageDigest
import java.security.SecureRandom
import kotlin.experimental.and

/**
* A combined crypto mechanism of
Expand Down Expand Up @@ -67,15 +66,24 @@ class HybridCrypto private constructor() {
}

private fun sha512(message: String): String {
val bytes = message.toByteArray()
val md = MessageDigest.getInstance("SHA-512")
val digest = md.digest(message.toByteArray())
val builder = StringBuilder()
for (i in digest.indices) {
builder.append(((digest[i] and 0xff.toByte()) + 0x100)
.toString(16)
.substring(1))
}
return builder.toString()
val digest = md.digest(bytes)
return digest.fold("") { str, it -> str + "%02x".format(it) }

// val bytes = input.toByteArray()
// val md = MessageDigest.getInstance("SHA-512")
// val digest = md.digest(bytes)
// return digest.fold("") { str, it -> str + "%02x".format(it) }
// val md = MessageDigest.getInstance("SHA-512")
// val digest = md.digest(message.toByteArray())
// val builder = StringBuilder()
// for (i in digest.indices) {
// builder.append(((digest[i] and 0xff.toByte()) + 0x100)
// .toString(16)
// .substring(1))
// }
// return builder.toString()
}

data class Configuration(
Expand Down

0 comments on commit 649ea7f

Please sign in to comment.