commit c7705db7e3b99aaac7ec2824c531656e3a086023 Author: Paul Date: Sun Oct 18 21:57:41 2020 +0200 inital commit diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..73f69e0 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/artifacts/RSA_KeyGenerator_jar.xml b/.idea/artifacts/RSA_KeyGenerator_jar.xml new file mode 100644 index 0000000..56c0aee --- /dev/null +++ b/.idea/artifacts/RSA_KeyGenerator_jar.xml @@ -0,0 +1,8 @@ + + + $PROJECT_DIR$ + + + + + \ No newline at end of file diff --git a/.idea/description.html b/.idea/description.html new file mode 100644 index 0000000..db5f129 --- /dev/null +++ b/.idea/description.html @@ -0,0 +1 @@ +Simple Java application that includes a class with main() method \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..05cb644 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..de46c1a --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/project-template.xml b/.idea/project-template.xml new file mode 100644 index 0000000..1f08b88 --- /dev/null +++ b/.idea/project-template.xml @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/RSA_KeyGenerator.iml b/RSA_KeyGenerator.iml new file mode 100644 index 0000000..d5c0743 --- /dev/null +++ b/RSA_KeyGenerator.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/RSA_KeyGenerator.jar b/RSA_KeyGenerator.jar new file mode 100644 index 0000000..cae6565 Binary files /dev/null and b/RSA_KeyGenerator.jar differ diff --git a/Readme.txt b/Readme.txt new file mode 100644 index 0000000..2a378a1 --- /dev/null +++ b/Readme.txt @@ -0,0 +1,80 @@ +Name: Paul Lödige +Matrikel: 15405036 + +Die Schlüsselgrößen, die von dem KeyPairGenerator ausgegeben werden sind sehr merkwürdig. +Ich habe bei meinem Code dadrauf geachtet. dass das Produkt aus private und public key die angefragte Größe entspricht. + +Da das Programm sehr lange zum laufen braucht (.jar beigefügt) folgt eine Beispielausgabe: + +0) 1024 Bit mit KeyPairGenerator: 137ms PrivKeySize: 5070 PubKeySize: 1294 ProductSize: 6364 +1) 1024 Bit mit KeyPairGenerator: 79ms PrivKeySize: 5070 PubKeySize: 1294 ProductSize: 6364 +2) 1024 Bit mit KeyPairGenerator: 143ms PrivKeySize: 5070 PubKeySize: 1294 ProductSize: 6364 +3) 1024 Bit mit KeyPairGenerator: 68ms PrivKeySize: 5062 PubKeySize: 1294 ProductSize: 6356 +4) 1024 Bit mit KeyPairGenerator: 76ms PrivKeySize: 5086 PubKeySize: 1294 ProductSize: 6380 +5) 1024 Bit mit KeyPairGenerator: 111ms PrivKeySize: 5078 PubKeySize: 1294 ProductSize: 6372 +6) 1024 Bit mit KeyPairGenerator: 111ms PrivKeySize: 5078 PubKeySize: 1294 ProductSize: 6372 +7) 1024 Bit mit KeyPairGenerator: 37ms PrivKeySize: 5070 PubKeySize: 1294 ProductSize: 6364 +8) 1024 Bit mit KeyPairGenerator: 72ms PrivKeySize: 5078 PubKeySize: 1294 ProductSize: 6372 +9) 1024 Bit mit KeyPairGenerator: 51ms PrivKeySize: 5062 PubKeySize: 1294 ProductSize: 6356 +Durschnittliche Laufzeit: 88.5ms +----------------------------------------------------- +0) 2048 Bit mit KeyPairGenerator: 186ms PrivKeySize: 9742 PubKeySize: 2350 ProductSize: 12092 +1) 2048 Bit mit KeyPairGenerator: 40ms PrivKeySize: 9750 PubKeySize: 2350 ProductSize: 12100 +2) 2048 Bit mit KeyPairGenerator: 56ms PrivKeySize: 9734 PubKeySize: 2350 ProductSize: 12084 +3) 2048 Bit mit KeyPairGenerator: 96ms PrivKeySize: 9734 PubKeySize: 2350 ProductSize: 12084 +4) 2048 Bit mit KeyPairGenerator: 129ms PrivKeySize: 9734 PubKeySize: 2350 ProductSize: 12084 +5) 2048 Bit mit KeyPairGenerator: 126ms PrivKeySize: 9726 PubKeySize: 2350 ProductSize: 12076 +6) 2048 Bit mit KeyPairGenerator: 73ms PrivKeySize: 9726 PubKeySize: 2350 ProductSize: 12076 +7) 2048 Bit mit KeyPairGenerator: 72ms PrivKeySize: 9734 PubKeySize: 2350 ProductSize: 12084 +8) 2048 Bit mit KeyPairGenerator: 178ms PrivKeySize: 9726 PubKeySize: 2350 ProductSize: 12076 +9) 2048 Bit mit KeyPairGenerator: 150ms PrivKeySize: 9734 PubKeySize: 2350 ProductSize: 12084 +Durschnittliche Laufzeit: 110.6ms +----------------------------------------------------- +0) 4096 Bit mit KeyPairGenerator: 1428ms PrivKeySize: 18982 PubKeySize: 4398 ProductSize: 23380 +1) 4096 Bit mit KeyPairGenerator: 478ms PrivKeySize: 18998 PubKeySize: 4398 ProductSize: 23396 +2) 4096 Bit mit KeyPairGenerator: 335ms PrivKeySize: 18990 PubKeySize: 4398 ProductSize: 23388 +3) 4096 Bit mit KeyPairGenerator: 2410ms PrivKeySize: 18990 PubKeySize: 4398 ProductSize: 23388 +4) 4096 Bit mit KeyPairGenerator: 2583ms PrivKeySize: 18998 PubKeySize: 4398 ProductSize: 23396 +5) 4096 Bit mit KeyPairGenerator: 1101ms PrivKeySize: 18990 PubKeySize: 4398 ProductSize: 23388 +6) 4096 Bit mit KeyPairGenerator: 386ms PrivKeySize: 18982 PubKeySize: 4398 ProductSize: 23380 +7) 4096 Bit mit KeyPairGenerator: 346ms PrivKeySize: 18998 PubKeySize: 4398 ProductSize: 23396 +8) 4096 Bit mit KeyPairGenerator: 1657ms PrivKeySize: 18982 PubKeySize: 4398 ProductSize: 23380 +9) 4096 Bit mit KeyPairGenerator: 1853ms PrivKeySize: 18998 PubKeySize: 4398 ProductSize: 23396 +Durschnittliche Laufzeit: 1257.7ms +----------------------------------------------------- +0) 1024 Bit mit BigInteger: 105ms PrivKeySize: 512 PubKeySize: 512 ProductSize: 1024 +1) 1024 Bit mit BigInteger: 679ms PrivKeySize: 512 PubKeySize: 512 ProductSize: 1024 +2) 1024 Bit mit BigInteger: 130ms PrivKeySize: 512 PubKeySize: 512 ProductSize: 1024 +3) 1024 Bit mit BigInteger: 255ms PrivKeySize: 512 PubKeySize: 512 ProductSize: 1024 +4) 1024 Bit mit BigInteger: 475ms PrivKeySize: 512 PubKeySize: 512 ProductSize: 1024 +5) 1024 Bit mit BigInteger: 179ms PrivKeySize: 512 PubKeySize: 512 ProductSize: 1024 +6) 1024 Bit mit BigInteger: 127ms PrivKeySize: 512 PubKeySize: 512 ProductSize: 1024 +7) 1024 Bit mit BigInteger: 167ms PrivKeySize: 512 PubKeySize: 512 ProductSize: 1024 +8) 1024 Bit mit BigInteger: 657ms PrivKeySize: 512 PubKeySize: 512 ProductSize: 1024 +9) 1024 Bit mit BigInteger: 19ms PrivKeySize: 512 PubKeySize: 512 ProductSize: 1024 +Durschnittliche Laufzeit: 279.3ms +----------------------------------------------------- +0) 2048 Bit mit BigInteger: 3200ms PrivKeySize: 1024 PubKeySize: 1024 ProductSize: 2048 +1) 2048 Bit mit BigInteger: 2789ms PrivKeySize: 1024 PubKeySize: 1024 ProductSize: 2048 +2) 2048 Bit mit BigInteger: 8340ms PrivKeySize: 1024 PubKeySize: 1024 ProductSize: 2048 +3) 2048 Bit mit BigInteger: 2868ms PrivKeySize: 1024 PubKeySize: 1024 ProductSize: 2048 +4) 2048 Bit mit BigInteger: 426ms PrivKeySize: 1024 PubKeySize: 1024 ProductSize: 2048 +5) 2048 Bit mit BigInteger: 1465ms PrivKeySize: 1024 PubKeySize: 1024 ProductSize: 2048 +6) 2048 Bit mit BigInteger: 2577ms PrivKeySize: 1024 PubKeySize: 1024 ProductSize: 2048 +7) 2048 Bit mit BigInteger: 666ms PrivKeySize: 1024 PubKeySize: 1024 ProductSize: 2048 +8) 2048 Bit mit BigInteger: 430ms PrivKeySize: 1024 PubKeySize: 1024 ProductSize: 2048 +9) 2048 Bit mit BigInteger: 2356ms PrivKeySize: 1024 PubKeySize: 1024 ProductSize: 2048 +Durschnittliche Laufzeit: 2511.7ms +----------------------------------------------------- +0) 4096 Bit mit BigInteger: 10017ms PrivKeySize: 2048 PubKeySize: 2048 ProductSize: 4096 +1) 4096 Bit mit BigInteger: 41918ms PrivKeySize: 2048 PubKeySize: 2048 ProductSize: 4096 +2) 4096 Bit mit BigInteger: 60839ms PrivKeySize: 2048 PubKeySize: 2048 ProductSize: 4096 +3) 4096 Bit mit BigInteger: 50729ms PrivKeySize: 2048 PubKeySize: 2048 ProductSize: 4096 +4) 4096 Bit mit BigInteger: 40834ms PrivKeySize: 2048 PubKeySize: 2048 ProductSize: 4096 +5) 4096 Bit mit BigInteger: 11870ms PrivKeySize: 2048 PubKeySize: 2048 ProductSize: 4096 +6) 4096 Bit mit BigInteger: 67847ms PrivKeySize: 2048 PubKeySize: 2048 ProductSize: 4096 +7) 4096 Bit mit BigInteger: 6077ms PrivKeySize: 2048 PubKeySize: 2048 ProductSize: 4096 +8) 4096 Bit mit BigInteger: 74448ms PrivKeySize: 2048 PubKeySize: 2048 ProductSize: 4096 +9) 4096 Bit mit BigInteger: 66870ms PrivKeySize: 2048 PubKeySize: 2048 ProductSize: 4096 +Durschnittliche Laufzeit: 43144.9ms +----------------------------------------------------- diff --git a/out/production/RSA_KeyGenerator/META-INF/MANIFEST.MF b/out/production/RSA_KeyGenerator/META-INF/MANIFEST.MF new file mode 100644 index 0000000..74bc389 --- /dev/null +++ b/out/production/RSA_KeyGenerator/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: tech.loedige.Main + diff --git a/out/production/RSA_KeyGenerator/tech/loedige/Main.class b/out/production/RSA_KeyGenerator/tech/loedige/Main.class new file mode 100644 index 0000000..f733355 Binary files /dev/null and b/out/production/RSA_KeyGenerator/tech/loedige/Main.class differ diff --git a/src/META-INF/MANIFEST.MF b/src/META-INF/MANIFEST.MF new file mode 100644 index 0000000..74bc389 --- /dev/null +++ b/src/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: tech.loedige.Main + diff --git a/src/tech/loedige/Main.java b/src/tech/loedige/Main.java new file mode 100644 index 0000000..c8b2424 --- /dev/null +++ b/src/tech/loedige/Main.java @@ -0,0 +1,98 @@ +package tech.loedige; + +import java.math.BigInteger; +import java.security.KeyPair; +import java.security.KeyPairGenerator; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Random; +import java.util.concurrent.Callable; +import java.util.function.Function; + +public class Main { + + public static void main(String[] args) throws Exception { + final int numberOfRuns = 10; + long start=0; + long finish = 0; + List trialsList = new ArrayList<>(); + long[] trials = new long[numberOfRuns]; + BigInteger[] KeyPair; + + //average the RSA key generation 10 times for 1024, 2048 and 4096 bit using the KeyPairGenerator + getTimesAndAverage(()->{return generateRSAWithLibrary(1024);},10,"1024 Bit mit KeyPairGenerator"); + getTimesAndAverage(()->{return generateRSAWithLibrary(2048);},10,"2048 Bit mit KeyPairGenerator"); + getTimesAndAverage(()->{return generateRSAWithLibrary(4096);},10,"4096 Bit mit KeyPairGenerator"); + + //average the RSA key generation 10 times for 1024, 2048 and 4096 bit using the sef written function + getTimesAndAverage(()->{return generateRSAWithBigInteger(1024);},10,"1024 Bit mit BigInteger"); + getTimesAndAverage(()->{return generateRSAWithBigInteger(2048);},10,"2048 Bit mit BigInteger"); + getTimesAndAverage(()->{return generateRSAWithBigInteger(4096);},10,"4096 Bit mit BigInteger"); + + } + + private static BigInteger[] generateRSAWithLibrary(int bitLength){ + try { + KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA"); + keyPairGenerator.initialize(bitLength); + KeyPair keyPair = keyPairGenerator.generateKeyPair(); + return new BigInteger[]{new BigInteger(keyPair.getPrivate().getEncoded()), new BigInteger(keyPair.getPublic().getEncoded())}; + + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + return null; + } + } + + private static void getTimesAndAverage(Callable function, int numberOfRuns, String functionName) throws Exception { + long start=0; + long finish=0; + List trialTimesList = new ArrayList<>(); + long[] trialTimes = new long[numberOfRuns]; + BigInteger[] KeyPair; + + for(int i = 0; i