Skip to content

Commit

Permalink
Aggiunte nuove codifiche e miglioramento generale
Browse files Browse the repository at this point in the history
Implementata la codifica Base32 e la sua versione modificata Base32-C che utilizza il carattere '9' per il padding, rimossi import non utilizzati, implementato un sistema di rimozione dei caratteri \r \n in fase di decrypt
  • Loading branch information
FrancescoValentini committed Oct 8, 2023
1 parent 7c1f372 commit 131c1a5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
1 change: 1 addition & 0 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="miglayout15-swing.jar" sourcepath="miglayout-src.zip"/>
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/bcprov-ext-jdk18on-176"/>
<classpathentry kind="lib" path="D:/EclipseWorkspaces/Libraries/commons-codec-1.16.0.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
16 changes: 16 additions & 0 deletions src/it/HackerInside/TextEncryptionUtility/AES256.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.SecretKeySpec;

import org.apache.commons.codec.binary.Base32;

import technology.zeroalpha.security.pgpwordlist.InvalidHexValueException;
import technology.zeroalpha.security.pgpwordlist.PGPWordListConverter;

Expand Down Expand Up @@ -162,6 +165,12 @@ public static String encryptDecryptString(int mode, String input, SecretKey key,
}else if(encoding.equalsIgnoreCase("base36")) {// Base36 Encoding
return Base36.encode(os.toByteArray());

}else if(encoding.equalsIgnoreCase("base32")) {// Base32 Encoding
Base32 base32 = new Base32();
return base32.encodeAsString(os.toByteArray());
}else if(encoding.equalsIgnoreCase("base32-c")) {// Base32-C Encoding
Base32 base32 = new Base32();
return base32.encodeAsString(os.toByteArray()).replace('=', '9');
}
else {
return bytesToHex(os.toByteArray());
Expand All @@ -188,6 +197,13 @@ else if(mode==Cipher.DECRYPT_MODE){
}
}else if(encoding.equalsIgnoreCase("base36")) {// Base36 Decoding
decodedData = Base36.decode(input);
}else if(encoding.equalsIgnoreCase("base32")) {// Base32 Encoding
Base32 base32 = new Base32();
decodedData = base32.decode(input);
}else if(encoding.equalsIgnoreCase("base32-c")) { // Base32-C
Base32 base32 = new Base32();
input = input.replace('9', '=');
decodedData = base32.decode(input);
}

is = new BufferedInputStream(new ByteArrayInputStream(decodedData));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private void initialize() {
cmbEncoding.setBounds(93, 11, 200, 36);
panel.add(cmbEncoding);

cmbEncoding.setModel(new DefaultComboBoxModel(new String[] {"Base64", "Base58", "Hex", "PGP Word list", "Base36"}));
cmbEncoding.setModel(new DefaultComboBoxModel(new String[] {"Base64", "Base58", "Hex", "PGP Word list", "Base36", "Base32", "Base32-C"}));

JCheckBox chckbCompression = new JCheckBox("GZIP Compression");
chckbCompression.setBackground(Color.WHITE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import java.security.Security;
import java.security.cert.CertificateException;
import java.util.Enumeration;
import java.util.Random;
import java.util.Scanner;
import java.util.prefs.Preferences;
import java.awt.event.MouseWheelEvent;
Expand Down Expand Up @@ -230,8 +229,11 @@ public void actionPerformed(ActionEvent e) {
String encryptedData = "";
int encoding = prefs.getInt("encoding", 0);
encryptedData = txtbData.getText().toString();

encryptedData = encryptedData.replace("\n", "");
encryptedData = encryptedData.replace("\r", "");

if(encoding !=3) // Rimuove gli spazi se e solo se l'opzione di codifica non è PGP Wordlist
if(encoding !=3) // Rimuove gli spazi se e solo se l'opzione di codifica non è PGP Wordlist
encryptedData = encryptedData.replace(" ", "");

try {
Expand Down Expand Up @@ -349,6 +351,10 @@ else if(encoding == 3)
encrypted = AES256.encryptDecryptString(Cipher.ENCRYPT_MODE, text, key,"pgpWordlist",compression);
else if(encoding == 4)
encrypted = AES256.encryptDecryptString(Cipher.ENCRYPT_MODE, text, key,"base36",compression);
else if(encoding == 5)
encrypted = AES256.encryptDecryptString(Cipher.ENCRYPT_MODE, text, key,"base32",compression);
else if(encoding == 6)
encrypted = AES256.encryptDecryptString(Cipher.ENCRYPT_MODE, text, key,"base32-c",compression);


return encrypted;
Expand All @@ -365,11 +371,14 @@ else if(encoding == 1)
decrypted = AES256.encryptDecryptString(Cipher.DECRYPT_MODE, text, key,"base58",compression);
else if(encoding == 2)
decrypted = AES256.encryptDecryptString(Cipher.DECRYPT_MODE, text, key,"hex",compression);

else if(encoding == 3)
decrypted = AES256.encryptDecryptString(Cipher.DECRYPT_MODE, text, key,"pgpWordlist",compression);
else if(encoding == 4)
decrypted = AES256.encryptDecryptString(Cipher.DECRYPT_MODE, text, key,"base36",compression);
else if(encoding == 5)
decrypted = AES256.encryptDecryptString(Cipher.DECRYPT_MODE, text, key,"base32",compression);
else if(encoding == 6)
decrypted = AES256.encryptDecryptString(Cipher.DECRYPT_MODE, text, key,"base32-c",compression);
return decrypted;
}

Expand Down

0 comments on commit 131c1a5

Please sign in to comment.