Skip to content

Instantly share code, notes, and snippets.

@Frycos
Created February 3, 2023 23:05
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save Frycos/d7ec4de07123f78cc37d29890dce0313 to your computer and use it in GitHub Desktop.
Save Frycos/d7ec4de07123f78cc37d29890dce0313 to your computer and use it in GitHub Desktop.
package com.mine;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
import org.apache.commons.codec.binary.Base64;
import com.linoma.security.commons.crypto.CryptoException;
import com.linoma.security.core.crypto.StandardEncryptionEngine;
public class CryptorHelper {
public static void main(String[] args) throws Exception, Exception {
/* */ final byte[] IV = {
/* 41 */ 65, 69, 83, 47, 67, 66, 67, 47, 80, 75, 67, 83, 53, 80, 97, 100 };
StandardEncryptionEngine see = new StandardEncryptionEngine(getInitializationValue(), IV, "AES", "AES/CBC/PKCS5Padding");
Path path = Paths.get("/home/user/tmp/calc.bin");
byte[] data = Files.readAllBytes(path);
System.out.println("[+] Encrypted: " + new String(Base64.encodeBase64(see.encrypt(data)), "UTF-8"));
}
/* */ private static byte[] getInitializationValue() throws Exception {
/* 180 */ byte[] arrayOfByte1 = { 103, 111, 64, 110, 121, 119, 104, 101, 114, 101, 76, 105, 99, 101, 110, 115, 101, 80, 64, 36, 36, 119, 114, 100 };
/* */
/* */
/* 183 */ byte[] arrayOfByte2 = { -19, 45, -32, -73, 65, 123, -7, 85 };
/* 184 */ char c1 = '┿';
/* 185 */ char c2 = 'Ā';
/* */
/* 187 */ SecretKeyFactory secretKeyFactory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
/* 188 */ PBEKeySpec pBEKeySpec = new PBEKeySpec((new String(arrayOfByte1, "UTF-8")).toCharArray(), arrayOfByte2, c1, c2);
/* 189 */ SecretKey secretKey = secretKeyFactory.generateSecret(pBEKeySpec);
/* 190 */ return secretKey.getEncoded();
/* */ }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment