gnunet-svn
[Top][All Lists]
Advanced

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

[libeufin] 02/02: wip: EBICS E002 encryption


From: gnunet
Subject: [libeufin] 02/02: wip: EBICS E002 encryption
Date: Mon, 04 Nov 2019 11:40:59 +0100

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

dold pushed a commit to branch master
in repository libeufin.

commit e30e4700e165ec5c38d21a9619b4f24ef8f0f21a
Author: Florian Dold <address@hidden>
AuthorDate: Mon Nov 4 11:40:54 2019 +0100

    wip: EBICS E002 encryption
---
 sandbox/src/main/kotlin/CryptoUtil.kt     | 24 ++++++++++++++++++++++++
 sandbox/src/main/kotlin/Main.kt           |  3 +--
 sandbox/src/test/kotlin/CryptoUtilTest.kt |  7 +++++++
 3 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/sandbox/src/main/kotlin/CryptoUtil.kt 
b/sandbox/src/main/kotlin/CryptoUtil.kt
index 20f5d52..b557bcd 100644
--- a/sandbox/src/main/kotlin/CryptoUtil.kt
+++ b/sandbox/src/main/kotlin/CryptoUtil.kt
@@ -19,16 +19,20 @@
 
 package tech.libeufin.sandbox
 
+import org.bouncycastle.jce.provider.BouncyCastleProvider
 import java.lang.Exception
 import java.math.BigInteger
 import java.security.KeyFactory
 import java.security.KeyPairGenerator
+import java.security.PrivateKey
 import java.security.PublicKey
 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
+import javax.crypto.Cipher
+import javax.crypto.KeyGenerator
 
 /**
  * RSA key pair.
@@ -39,7 +43,16 @@ data class RsaCrtKeyPair(val private: RSAPrivateCrtKey, val 
public: RSAPublicKey
  * Helpers for dealing with crypographic operations in EBICS / LibEuFin.
  */
 class CryptoUtil {
+
+    data class EncryptionResult(
+        val encryptedTransactionKey: ByteArray,
+        val pubKeyDigest: ByteArray,
+        val encryptedData: ByteArray
+    )
+
     companion object {
+        private val bouncyCastleProvider = BouncyCastleProvider()
+
         /**
          * Load an RSA private key from its binary PKCS#8 encoding.
          */
@@ -106,5 +119,16 @@ class CryptoUtil {
             val tmp = RSAPublicKeySpec(modulusBigInt, exponentBigInt)
             return keyFactory.generatePublic(tmp) as RSAPublicKey
         }
+
+        fun encryptEbicsE002(data: ByteArray, signingPrivateKey: 
RSAPrivateCrtKey) {
+            val prov = BouncyCastleProvider()
+            val keygen = KeyGenerator.getInstance("AES", bouncyCastleProvider)
+            keygen.init(128)
+            val transportKey = keygen.generateKey()
+
+            val cipher = Cipher.getInstance("AES/CBC/X9.23Padding", 
bouncyCastleProvider)
+            cipher.init(Cipher.ENCRYPT_MODE, transportKey)
+            val encryptedData = cipher.doFinal(data)
+        }
     }
 }
diff --git a/sandbox/src/main/kotlin/Main.kt b/sandbox/src/main/kotlin/Main.kt
index 91f9649..6f40c6e 100644
--- a/sandbox/src/main/kotlin/Main.kt
+++ b/sandbox/src/main/kotlin/Main.kt
@@ -323,8 +323,7 @@ private suspend fun ApplicationCall.ebicsweb() {
         "ebicsNoPubKeyDigestsRequest" -> {
             val requestJaxb = 
XMLUtil.convertDomToJaxb(EbicsNoPubKeyDigestsRequest::class.java, bodyDocument)
             val staticHeader = requestJaxb.value.header.static
-            val orderType = staticHeader.orderDetails.orderType
-            when (orderType) {
+            when (val orderType = staticHeader.orderDetails.orderType) {
                 "HPB" -> {
                     val subscriberKeys = transaction {
                         val ebicsSubscriber =
diff --git a/sandbox/src/test/kotlin/CryptoUtilTest.kt 
b/sandbox/src/test/kotlin/CryptoUtilTest.kt
index 3ea9cfe..4e2c360 100644
--- a/sandbox/src/test/kotlin/CryptoUtilTest.kt
+++ b/sandbox/src/test/kotlin/CryptoUtilTest.kt
@@ -56,4 +56,11 @@ class CryptoUtilTest {
         assertEquals(keyPair.private, otherKeyPair.private)
         assertEquals(keyPair.public, otherKeyPair.public)
     }
+
+    @Test
+    fun testEbicsE002() {
+        val data = "Hello, World!"
+        val keyPair = CryptoUtil.generateRsaKeyPair(1024)
+        CryptoUtil.encryptEbicsE002(data.toByteArray(), keyPair.private)
+    }
 }
\ 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]