package de.bwlehrpool.bwlp_guac; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import javax.crypto.BadPaddingException; import javax.crypto.Cipher; import javax.crypto.IllegalBlockSizeException; import javax.crypto.NoSuchPaddingException; import javax.crypto.spec.SecretKeySpec; public class WeakCrypto { private static byte[] reverseBits(byte[] b) { byte[] result = new byte[b.length]; for (int i = 0; i < b.length; i++) { result[i] = reverseBits(b[i]); } return result; } private static byte reverseBits(byte input) { byte result = 0x00; for (int i = 0; i < 8; i++) { result |= ((byte) ((input & (0x01 << i)) >>> i) << 7 - i); } return result; } public static byte[] vncEncrypt(byte[] pw_bytes, byte[] challenge) { Cipher des; try { des = Cipher.getInstance("DES/ECB/NoPadding"); des.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(reverseBits(pw_bytes), 0, pw_bytes.length, "DES")); return des.doFinal(challenge); } catch (InvalidKeyException | NoSuchAlgorithmException | NoSuchPaddingException | IllegalBlockSizeException | BadPaddingException e) { // TODO Auto-generated catch block e.printStackTrace(); } return new byte[16]; } }