init project. AES_GCM, placeholders

This commit is contained in:
2026-05-22 17:15:35 -04:00
commit ae9d5fc8b0
8 changed files with 128 additions and 0 deletions
+30
View File
@@ -0,0 +1,30 @@
### IntelliJ IDEA ###
out/
!**/src/main/**/out/
!**/src/test/**/out/
.kotlin
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store
+10
View File
@@ -0,0 +1,10 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Ignored default folder with query files
/queries/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" default="true" project-jdk-name="openjdk-26" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
+8
View File
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/XACrypto.iml" filepath="$PROJECT_DIR$/XACrypto.iml" />
</modules>
</component>
</project>
Generated
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
+11
View File
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
@@ -0,0 +1,5 @@
package main.java.de.caydenno1.xacrypto;
public class XACrypto {
private XACrypto() {}
}
@@ -0,0 +1,52 @@
package main.java.de.caydenno1.xacrypto.encryption;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.GCMParameterSpec;
import java.security.SecureRandom;
import java.util.Base64;
public class AES_GCM {
private static final String AES = "AES";
private static final String AES_GCM = "AES/GCM/NoPadding";
private AES_GCM() {}
public static SecretKey genKey(int bits) throws Exception {
KeyGenerator g = KeyGenerator.getInstance(AES);
g.init(bits);
return g.generateKey();
}
public static String encrypt(String pln, SecretKey k, int TAG, int IV) throws Exception {
byte[] iv = new byte[IV];
new SecureRandom().nextBytes(iv);
Cipher c = Cipher.getInstance(AES_GCM);
c.init(Cipher.ENCRYPT_MODE, k, new GCMParameterSpec(TAG, iv));
byte[] citext = c.doFinal(pln.getBytes());
byte[] comb = new byte[iv.length + citext.length];
System.arraycopy(iv, 0, comb, 0, iv.length);
System.arraycopy(citext, 0, comb, iv.length, citext.length);
return Base64.getEncoder().encodeToString(comb);
}
public static String decrypt(String enc, SecretKey k, int TAG, int IV) throws Exception {
byte[] dat = Base64.getDecoder().decode(enc);
byte[] iv = new byte[IV];
byte[] cit = new byte[dat.length - IV];
System.arraycopy(dat, 0, iv, 0, IV);
System.arraycopy(dat, IV, cit, 0, cit.length);
Cipher ci = Cipher.getInstance(AES_GCM);
ci.init(Cipher.DECRYPT_MODE, k, new GCMParameterSpec(TAG, iv));
return new String(ci.doFinal(cit));
}
}