package Weak_Encryption; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.util.logging.Logger; import javax.crypto.BadPaddingException; import javax.crypto.Cipher; import javax.crypto.IllegalBlockSizeException; import javax.crypto.NoSuchPaddingException; import javax.crypto.spec.SecretKeySpec; public class Weak_Encryption { static final Logger log = Logger.getLogger("local-logger"); public String bad() { String data = "root"; /* init data */ String sKey = "sKey"; Cipher cipher = null; try { SecretKeySpec key = new SecretKeySpec(sKey.getBytes(), "DES"); cipher = Cipher.getInstance("DES"); // bad 寮卞姞瀵� cipher.init(Cipher.DECRYPT_MODE, key); } catch (NoSuchPaddingException e) { log.info("error"); } catch (NoSuchAlgorithmException e) { log.info("error"); } catch (InvalidKeyException e) { log.info("InvalidKeyException"); } String pw = ""; try { if(cipher != null){ pw = new String(cipher.doFinal(data.getBytes())); } } catch (IllegalBlockSizeException e) { log.info("error"); } catch (BadPaddingException e) { log.info("error"); } String cipertext = pw; return cipertext; } public String good() { String data = "root"; /* init data */ String sKey = "sKey"; Cipher cipher = null; try { SecretKeySpec key = new SecretKeySpec(sKey.getBytes(), "AES"); cipher = Cipher.getInstance("AES"); // good 寮卞姞瀵� cipher.init(Cipher.DECRYPT_MODE, key); } catch ( NoSuchPaddingException e) { log.info("error"); } catch (NoSuchAlgorithmException e) { log.info("error"); } catch (InvalidKeyException e) { log.info("InvalidKeyException"); } String pw = ""; try { if(cipher != null){ pw = new String(cipher.doFinal(data.getBytes())); } } catch (IllegalBlockSizeException e) { log.info("error"); } catch (BadPaddingException e) { log.info("error"); } String cipertext = pw; return cipertext; } }