Last active
November 29, 2019 17:28
-
-
Save pawlos/4245cbca80944e246ce6d6b614389083 to your computer and use it in GitHub Desktop.
Solution for Flare-On 2019 Lvl 3 - Flarebear
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.crypto.Cipher; | |
import javax.crypto.SecretKey; | |
import javax.crypto.SecretKeyFactory; | |
import javax.crypto.spec.IvParameterSpec; | |
import javax.crypto.spec.PBEKeySpec; | |
import javax.crypto.spec.SecretKeySpec; | |
import java.nio.charset.Charset; | |
import javax.crypto.*; | |
import java.security.*; | |
import java.security.spec.*; | |
import java.nio.file.Paths; | |
import java.nio.file.Files; | |
import java.nio.file.Path; | |
import java.nio.file.*; | |
import java.io.IOException; | |
import org.bouncycastle.jce.provider.BouncyCastleProvider; | |
public final class FlareBearActivity { | |
public static final void main(String[] args) throws IOException { | |
System.out.println("Flare-On 2019: "); | |
String password = getPassword(); | |
byte[] readBytes = Files.readAllBytes(Paths.get("ecstatic")); | |
byte[] readBytes2 = Files.readAllBytes(Paths.get("ecstatic2")); | |
System.out.println("Ecstatic: "+readBytes.length); | |
System.out.println("Ecstatic2: "+readBytes2.length); | |
try { | |
byte[] decrypt = decrypt(password, readBytes); | |
byte[] decrypt2 = decrypt(password, readBytes2); | |
Files.write(Paths.get("ecstatic.decrypted"), decrypt, StandardOpenOption.CREATE); | |
Files.write(Paths.get("ecstatic2.decrypted"), decrypt2, StandardOpenOption.CREATE); | |
}catch (Exception unused) { | |
System.out.println("Exception! "+unused); | |
} | |
System.out.println("Decrypted."); | |
} | |
public static final String getPassword() { | |
return "flareflareflareflare*BEARBEARBEARBEARBEARBEARBEARBEAR+yeahyeah"; | |
} | |
public static final byte[] decrypt(String str, byte[] bArr) throws NoSuchAlgorithmException, | |
InvalidKeySpecException, | |
NoSuchPaddingException, | |
InvalidKeyException, | |
IllegalBlockSizeException, | |
InvalidAlgorithmParameterException, | |
BadPaddingException { | |
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()); | |
String str2 = "UTF-8"; | |
Charset forName = Charset.forName(str2); | |
String str3 = "Charset.forName(charsetName)"; | |
byte[] bytes = "pawsitive_vibes!".getBytes(forName); | |
IvParameterSpec ivParameterSpec = new IvParameterSpec(bytes); | |
char[] charArray = str.toCharArray(); | |
Charset forName2 = Charset.forName(str2); | |
byte[] bytes2 = "NaClNaClNaCl".getBytes(forName2); | |
SecretKey generateSecret = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1").generateSecret(new PBEKeySpec(charArray, bytes2, 1234, 256)); | |
SecretKeySpec secretKeySpec = new SecretKeySpec(generateSecret.getEncoded(), "AES"); | |
Cipher instance = Cipher.getInstance("AES/CBC/PKCS7Padding"); //AES/CBC/PKCS7Padding | |
instance.init(2/*Cipher.DECRYPT_MODE*/, secretKeySpec, ivParameterSpec); //2 | |
byte[] doFinal = instance.doFinal(bArr); | |
return doFinal; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment