[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libeufin] branch master updated: fix up key format and key hash
From: |
gnunet |
Subject: |
[libeufin] branch master updated: fix up key format and key hash |
Date: |
Thu, 30 Jan 2020 16:44:04 +0100 |
This is an automated email from the git hooks/post-receive script.
dold pushed a commit to branch master
in repository libeufin.
The following commit(s) were added to refs/heads/master by this push:
new 8325a03 fix up key format and key hash
8325a03 is described below
commit 8325a033326725fcf193f0dae9c04e45c5ec5f97
Author: Florian Dold <address@hidden>
AuthorDate: Thu Jan 30 16:43:59 2020 +0100
fix up key format and key hash
---
nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt | 12 ++++++------
util/src/main/kotlin/CryptoUtil.kt | 4 ++--
util/src/main/kotlin/strings.kt | 9 +++++++++
3 files changed, 17 insertions(+), 8 deletions(-)
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
index 6bdab04..08649fb 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
@@ -334,12 +334,12 @@ fun main() {
)
hostID = subscriber.hostID
userIdLine = subscriber.userID
- esExponentLine =
signPubTmp.publicExponent.toByteArray().toHexString()
- esModulusLine =
signPubTmp.modulus.toByteArray().toHexString()
- encExponentLine =
encPubTmp.publicExponent.toByteArray().toHexString()
- encModulusLine =
encPubTmp.modulus.toByteArray().toHexString()
- authExponentLine =
authPubTmp.publicExponent.toByteArray().toHexString()
- authModulusLine =
authPubTmp.modulus.toByteArray().toHexString()
+ esExponentLine =
signPubTmp.publicExponent.toUnsignedHexString()
+ esModulusLine = signPubTmp.modulus.toUnsignedHexString()
+ encExponentLine =
encPubTmp.publicExponent.toUnsignedHexString()
+ encModulusLine = encPubTmp.modulus.toUnsignedHexString()
+ authExponentLine =
authPubTmp.publicExponent.toUnsignedHexString()
+ authModulusLine = authPubTmp.modulus.toUnsignedHexString()
esKeyHashLine =
CryptoUtil.getEbicsPublicKeyHash(signPubTmp).toHexString()
encKeyHashLine =
CryptoUtil.getEbicsPublicKeyHash(encPubTmp).toHexString()
authKeyHashLine =
CryptoUtil.getEbicsPublicKeyHash(authPubTmp).toHexString()
diff --git a/util/src/main/kotlin/CryptoUtil.kt
b/util/src/main/kotlin/CryptoUtil.kt
index bb3e427..e14cf67 100644
--- a/util/src/main/kotlin/CryptoUtil.kt
+++ b/util/src/main/kotlin/CryptoUtil.kt
@@ -121,9 +121,9 @@ object CryptoUtil {
*/
fun getEbicsPublicKeyHash(publicKey: RSAPublicKey): ByteArray {
val keyBytes = ByteArrayOutputStream()
-
keyBytes.writeBytes(publicKey.publicExponent.toByteArray().toHexString().toByteArray())
+
keyBytes.writeBytes(publicKey.publicExponent.toUnsignedHexString().toByteArray())
keyBytes.write(' '.toInt())
-
keyBytes.writeBytes(publicKey.modulus.toByteArray().toHexString().toByteArray())
+
keyBytes.writeBytes(publicKey.modulus.toUnsignedHexString().toByteArray())
val digest = MessageDigest.getInstance("SHA-256")
return digest.digest(keyBytes.toByteArray())
}
diff --git a/util/src/main/kotlin/strings.kt b/util/src/main/kotlin/strings.kt
index 6fdcfd3..b113e06 100644
--- a/util/src/main/kotlin/strings.kt
+++ b/util/src/main/kotlin/strings.kt
@@ -1,6 +1,8 @@
package tech.libeufin.util
+import java.math.BigInteger
import java.util.*
+
fun ByteArray.toHexString() : String {
return this.joinToString("") {
java.lang.String.format("%02x", it)
@@ -14,3 +16,10 @@ fun bytesToBase64(bytes: ByteArray): String {
fun base64ToBytes(encoding: String): ByteArray {
return Base64.getDecoder().decode(encoding)
}
+
+fun BigInteger.toUnsignedHexString(): String {
+ val signedValue = this.toByteArray()
+ require(signedValue[0] == 0.toByte()) { "value must be a positive
BigInteger" }
+ val bytes = Arrays.copyOfRange(signedValue, 1, signedValue.size)
+ return bytes.toHexString()
+}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
address@hidden.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [libeufin] branch master updated: fix up key format and key hash,
gnunet <=