gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libeufin] branch master updated (1c2a672 -> 43fa22d)


From: gnunet
Subject: [libeufin] branch master updated (1c2a672 -> 43fa22d)
Date: Wed, 30 Oct 2019 12:36:29 +0100

This is an automated email from the git hooks/post-receive script.

dold pushed a change to branch master
in repository libeufin.

    from 1c2a672  move to custom JAXB in kotlin, lots of refactoring
     new 2d29bdc  no more xjc
     new 43fa22d  crypto utils

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 sandbox/src/main/bash/jaxb.sh         |  3 --
 sandbox/src/main/kotlin/CryptoUtil.kt | 75 +++++++++++++++++++++++++++++++++++
 sandbox/src/test/kotlin/RsaTest.kt    | 31 ---------------
 3 files changed, 75 insertions(+), 34 deletions(-)
 delete mode 100755 sandbox/src/main/bash/jaxb.sh
 create mode 100644 sandbox/src/main/kotlin/CryptoUtil.kt
 delete mode 100644 sandbox/src/test/kotlin/RsaTest.kt

diff --git a/sandbox/src/main/bash/jaxb.sh b/sandbox/src/main/bash/jaxb.sh
deleted file mode 100755
index f3ea41a..0000000
--- a/sandbox/src/main/bash/jaxb.sh
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/bin/bash
-
-xjc -p $PACKAGE_NAME -d $DEST_DIR -b bindings.xjb $SCHEMA
diff --git a/sandbox/src/main/kotlin/CryptoUtil.kt 
b/sandbox/src/main/kotlin/CryptoUtil.kt
new file mode 100644
index 0000000..fb72d09
--- /dev/null
+++ b/sandbox/src/main/kotlin/CryptoUtil.kt
@@ -0,0 +1,75 @@
+/*
+ * This file is part of LibEuFin.
+ * Copyright (C) 2019 Stanisci and Dold.
+
+ * LibEuFin is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation; either version 3, or
+ * (at your option) any later version.
+
+ * LibEuFin is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General
+ * Public License for more details.
+
+ * You should have received a copy of the GNU Affero General Public
+ * License along with LibEuFin; see the file COPYING.  If not, see
+ * <http://www.gnu.org/licenses/>
+ */
+
+package tech.libeufin.sandbox
+
+import java.lang.Exception
+import java.security.KeyFactory
+import java.security.KeyPairGenerator
+import java.security.interfaces.RSAPrivateCrtKey
+import java.security.interfaces.RSAPublicKey
+import java.security.spec.PKCS8EncodedKeySpec
+import java.security.spec.RSAPublicKeySpec
+import java.security.spec.X509EncodedKeySpec
+
+/**
+ * RSA key pair.
+ */
+data class RsaCrtKeyPair(val private: RSAPrivateCrtKey, val public: 
RSAPublicKey)
+
+/**
+ * Helpers for dealing with crypographic operations in EBICS / LibEuFin.
+ */
+class CryptoUtil {
+    companion object {
+        fun loadRsaPrivateKey(encodedPrivateKey: ByteArray): RSAPrivateCrtKey {
+            val spec = PKCS8EncodedKeySpec(encodedPrivateKey)
+            val priv = KeyFactory.getInstance("RSA").generatePrivate(spec)
+            if (priv !is RSAPrivateCrtKey)
+                throw Exception("wrong encoding")
+            return priv
+        }
+        fun loadRsaPublicKey(encodedPublicKey: ByteArray): RSAPublicKey {
+            val spec = X509EncodedKeySpec(encodedPublicKey)
+            val pub = KeyFactory.getInstance("RSA").generatePublic(spec)
+            if (pub !is RSAPublicKey)
+                throw Exception("wrong encoding")
+            return pub
+        }
+        fun getRsaPublicFromPrivate(rsaPrivateCrtKey: RSAPrivateCrtKey): 
RSAPublicKey {
+            val spec = RSAPublicKeySpec(rsaPrivateCrtKey.modulus, 
rsaPrivateCrtKey.publicExponent)
+            val pub = KeyFactory.getInstance("RSA").generatePublic(spec)
+            if (pub !is RSAPublicKey)
+                throw Exception("wrong encoding")
+            return pub
+        }
+        fun generateRsaKeyPair(nbits: Int): RsaCrtKeyPair {
+            val gen = KeyPairGenerator.getInstance("RSA")
+            gen.initialize(nbits)
+            val pair = gen.genKeyPair()
+            val priv = pair.private
+            val pub = pair.public
+            if (priv !is RSAPrivateCrtKey)
+                throw Exception("key generation failed")
+            if (pub !is RSAPublicKey)
+                throw Exception("key generation failed")
+            return RsaCrtKeyPair(priv, pub)
+        }
+    }
+}
\ No newline at end of file
diff --git a/sandbox/src/test/kotlin/RsaTest.kt 
b/sandbox/src/test/kotlin/RsaTest.kt
deleted file mode 100644
index 836d88d..0000000
--- a/sandbox/src/test/kotlin/RsaTest.kt
+++ /dev/null
@@ -1,31 +0,0 @@
-package tech.libeufin.sandbox
-
-import org.junit.Test
-import java.math.BigInteger
-import java.util.*
-
-class RsaTest {
-
-    val publicModulus = BigInteger("65537")
-    val publicExponent = BigInteger(512, Random())
-
-    @Test
-    fun loadFromModulusAndExponent() {
-        val key = loadRsaPublicKey(publicExponent.toByteArray(), 
publicModulus.toByteArray())
-        println(key.toString())
-    }
-
-    /**
-     * Values generating helper.
-     */
-    @Test
-    fun getBase64Values() {
-
-        println(
-            "Modulus: 
${Base64.getEncoder().encodeToString(publicModulus.toByteArray())}"
-        )
-        println(
-            "Exponent: 
${Base64.getEncoder().encodeToString(publicExponent.toByteArray())}"
-        )
-    }
-}
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]