Create a gist now

Instantly share code, notes, and snippets.

// rename as HelloWorld.java :)
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.SecretKeySpec;
import sun.misc.BASE64Decoder;
public class HelloWorld{
public static void main(String[] args) throws Exception
{
String SECRET = "Bi528nDlNBcX9BcCC+ZqGQo1Oz01+GOWSmvxRj7jg1g=";
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
byte[] salt = "SampleSalt".getBytes();
String pin = "7498";
SecretKeySpec key = new SecretKeySpec(SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1").generateSecret(new PBEKeySpec(pin.toCharArray(), salt, 1000, 128)).getEncoded(), "AES");
cipher.init(2,key);
BASE64Decoder decoder = new BASE64Decoder();
System.out.println(new String(cipher.doFinal(decoder.decodeBuffer(SECRET)),"UTF-8"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment