gitshark

Clone repository

git clone https://gitshark.de/git/workaround/Gitshark.git
git clone git@gitshark.de:workaround/Gitshark.git

← Commits

๐Ÿ› (mirrors): Keep SecureRandom out of the native image heap

1ebd7774b61f16b91c40bea5eec1aefca1aae2cd ยท Michael Hainz ยท 2026-07-09T08:02:54Z

Changes

1 file changed, +4 -2

MODIFY src/main/java/de/workaround/mirror/SecretCrypto.java +4 -2
diff --git a/src/main/java/de/workaround/mirror/SecretCrypto.java b/src/main/java/de/workaround/mirror/SecretCrypto.java
index 9efeef9..0fae7a5 100644
--- a/src/main/java/de/workaround/mirror/SecretCrypto.java
+++ b/src/main/java/de/workaround/mirror/SecretCrypto.java
@@ -31,7 +31,9 @@
31 31
32 32 private static final int TAG_BITS = 128;
33 33
34 - private static final SecureRandom RANDOM = new SecureRandom();
34 + // instance field, not static: a build-time-initialized static SecureRandom would land in the
35 + // native image heap with a cached seed, which GraalVM rejects (and would be unsafe anyway)
36 + private final SecureRandom random = new SecureRandom();
35 37
36 38 private final SecretKeySpec key;
37 39
@@ -65,7 +67,7 @@
65 67 try
66 68 {
67 69 byte[] iv = new byte[IV_BYTES];
68 - RANDOM.nextBytes(iv);
70 + random.nextBytes(iv);
69 71 Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
70 72 cipher.init(Cipher.ENCRYPT_MODE, key, new GCMParameterSpec(TAG_BITS, iv));
71 73 byte[] ciphertext = cipher.doFinal(plaintext.getBytes(StandardCharsets.UTF_8));

Keyboard shortcuts

?Show this help
g hGo home
EscClose dialog