Format Test and update .expected

This commit is contained in:
Nicolas Will
2025-10-06 16:29:25 +02:00
parent e823d80f0c
commit 15e9bb9cc1
2 changed files with 18 additions and 30 deletions

View File

@@ -1,4 +1,4 @@
| Test.java:47:47:47:52 | Nonce | Reuse with nonce $@ | Test.java:56:47:56:52 | Nonce | Nonce | | Test.java:40:47:40:52 | Nonce | Reuse with nonce $@ | Test.java:49:47:49:52 | Nonce | Nonce |
| Test.java:56:47:56:52 | Nonce | Reuse with nonce $@ | Test.java:47:47:47:52 | Nonce | Nonce | | Test.java:49:47:49:52 | Nonce | Reuse with nonce $@ | Test.java:40:47:40:52 | Nonce | Nonce |
| Test.java:84:48:84:54 | Nonce | Reuse with nonce $@ | Test.java:90:49:90:55 | Nonce | Nonce | | Test.java:76:48:76:54 | Nonce | Reuse with nonce $@ | Test.java:82:49:82:55 | Nonce | Nonce |
| Test.java:90:49:90:55 | Nonce | Reuse with nonce $@ | Test.java:84:48:84:54 | Nonce | Nonce | | Test.java:82:49:82:55 | Nonce | Reuse with nonce $@ | Test.java:76:48:76:54 | Nonce | Nonce |

View File

@@ -1,46 +1,39 @@
package com.example.crypto.artifacts; package com.example.crypto.artifacts;
import java.security.*;
import javax.crypto.Cipher; import javax.crypto.Cipher;
import javax.crypto.KeyGenerator; import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey; import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.GCMParameterSpec;
import java.security.*;
import java.util.Base64;
import java.util.Properties;
import java.util.Random;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Arrays;
public class Test { public class Test {
public static SecretKey generateAESKey()throws Exception { public static SecretKey generateAESKey() throws Exception {
KeyGenerator keyGen = KeyGenerator.getInstance("AES"); KeyGenerator keyGen = KeyGenerator.getInstance("AES");
keyGen.init(256); keyGen.init(256);
return keyGen.generateKey(); return keyGen.generateKey();
} }
private static byte[] getRandomWrapper1() throws Exception {
private static byte[] getRandomWrapper1()throws Exception {
byte[] val = new byte[16]; byte[] val = new byte[16];
new SecureRandom().nextBytes(val); new SecureRandom().nextBytes(val);
return val; return val;
} }
private static byte[] getRandomWrapper2A()throws Exception { private static byte[] getRandomWrapper2A() throws Exception {
byte[] val; byte[] val;
val = getRandomWrapper1(); val = getRandomWrapper1();
funcA1(val); funcA1(val);
return val; return val;
} }
private static byte[] getRandomWrapper2b()throws Exception { private static byte[] getRandomWrapper2b() throws Exception {
byte[] val; byte[] val;
val = getRandomWrapper1(); val = getRandomWrapper1();
return val; return val;
} }
private static void funcA1(byte[] iv)throws Exception { private static void funcA1(byte[] iv) throws Exception {
IvParameterSpec ivSpec = new IvParameterSpec(iv); IvParameterSpec ivSpec = new IvParameterSpec(iv);
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
SecretKey key = generateAESKey(); SecretKey key = generateAESKey();
@@ -48,7 +41,7 @@ public class Test {
byte[] ciphertext = cipher.doFinal("Simple Test Data".getBytes()); byte[] ciphertext = cipher.doFinal("Simple Test Data".getBytes());
} }
private static void funcB1()throws Exception { private static void funcB1() throws Exception {
byte[] iv = getRandomWrapper2A(); byte[] iv = getRandomWrapper2A();
IvParameterSpec ivSpec = new IvParameterSpec(iv); IvParameterSpec ivSpec = new IvParameterSpec(iv);
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
@@ -57,7 +50,7 @@ public class Test {
byte[] ciphertext = cipher.doFinal("Simple Test Data".getBytes()); byte[] ciphertext = cipher.doFinal("Simple Test Data".getBytes());
} }
private static void funcA2()throws Exception { private static void funcA2() throws Exception {
byte[] iv = getRandomWrapper2b(); byte[] iv = getRandomWrapper2b();
IvParameterSpec ivSpec = new IvParameterSpec(iv); IvParameterSpec ivSpec = new IvParameterSpec(iv);
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
@@ -66,7 +59,7 @@ public class Test {
byte[] ciphertext = cipher.doFinal("Simple Test Data".getBytes()); byte[] ciphertext = cipher.doFinal("Simple Test Data".getBytes());
} }
private static void funcB2()throws Exception { private static void funcB2() throws Exception {
byte[] iv = getRandomWrapper2b(); byte[] iv = getRandomWrapper2b();
IvParameterSpec ivSpec = new IvParameterSpec(iv); IvParameterSpec ivSpec = new IvParameterSpec(iv);
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
@@ -75,7 +68,6 @@ public class Test {
byte[] ciphertext = cipher.doFinal("Simple Test Data".getBytes()); byte[] ciphertext = cipher.doFinal("Simple Test Data".getBytes());
} }
private static void funcA3() throws Exception { private static void funcA3() throws Exception {
byte[] iv = getRandomWrapper2b(); byte[] iv = getRandomWrapper2b();
IvParameterSpec ivSpec1 = new IvParameterSpec(iv); IvParameterSpec ivSpec1 = new IvParameterSpec(iv);
@@ -91,16 +83,12 @@ public class Test {
byte[] ciphertext2 = cipher2.doFinal("Simple Test Data".getBytes()); byte[] ciphertext2 = cipher2.doFinal("Simple Test Data".getBytes());
} }
public static void main(String[] args) { public static void main(String[] args) {
try{ try {
funcA2(); funcA2();
funcB1(); funcB1();
funcB2(); funcB2();
} } catch (Exception e) {
catch(Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }