// The Triple DES algorithm requires a trusted source of random bits SecureRandom sr = new SecureRandom(); //Create a Triple DES key object specification from the raw data. //Treat the bytes read from file as a hex string DESedeKeySpec dks = new DESedeKeySpec(Hex.fromString(keyString)); // Create a key factory and use it to turn the DESedeKeySpec into // a SecretKey object SecretKeyFactory keyFactory = SecretKeyFactory.getInstance( "DESede" ); SecretKey key = keyFactory.generateSecret( dks ); Cipher cipher = Cipher.getInstance("DESede/ECB/NoPadding"); // Initialize the cipher with the key cipher.init( Cipher.ENCRYPT_MODE, key ); //Get the input data padded with 'F' in a byte array byte[] data = Hex.fromString(XORResult); // The actual encryption step byte encryptedData[] = cipher.doFinal( data ); /**Triple DES Encryption End **/ //Convert the encrypted bytes to big int BigInteger bCiph = new BigInteger(encryptedData); //Dump the byte array to a temp string tempString = Hex.dumpString(getMagnitude(bCiph)); tempString = tempString.trim(); //If output contains hex A-F convert to //ASCII value of 3A-3F //Get the output string in a byte array byte outputStr[] = new byte[tempString.length()]; //Compare each byte for values A-F for (int hexCnt=0;hexCnt<tempString.length();hexCnt++) { outputStr[hexCnt] = (byte) tempString.charAt(hexCnt); } //Convert the output byte array to string encryptedPin = new String(outputStr); encryptedPin = encryptedPin.trim();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)