You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

Weak_Encryption.java 2.1 kB

3 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package Weak_Encryption;
  2. import java.security.InvalidKeyException;
  3. import java.security.NoSuchAlgorithmException;
  4. import java.util.logging.Logger;
  5. import javax.crypto.BadPaddingException;
  6. import javax.crypto.Cipher;
  7. import javax.crypto.IllegalBlockSizeException;
  8. import javax.crypto.NoSuchPaddingException;
  9. import javax.crypto.spec.SecretKeySpec;
  10. public class Weak_Encryption {
  11. static final Logger log = Logger.getLogger("local-logger");
  12. public String bad()
  13. {
  14. String data = "root"; /* init data */
  15. String sKey = "sKey";
  16. Cipher cipher = null;
  17. try {
  18. SecretKeySpec key = new SecretKeySpec(sKey.getBytes(), "DES");
  19. cipher = Cipher.getInstance("DES"); // bad 寮卞姞瀵�
  20. cipher.init(Cipher.DECRYPT_MODE, key);
  21. } catch (NoSuchPaddingException e) {
  22. log.info("error");
  23. } catch (NoSuchAlgorithmException e) {
  24. log.info("error");
  25. } catch (InvalidKeyException e) {
  26. log.info("InvalidKeyException");
  27. }
  28. String pw = "";
  29. try {
  30. if(cipher != null){
  31. pw = new String(cipher.doFinal(data.getBytes()));
  32. }
  33. } catch (IllegalBlockSizeException e) {
  34. log.info("error");
  35. } catch (BadPaddingException e) {
  36. log.info("error");
  37. }
  38. String cipertext = pw;
  39. return cipertext;
  40. }
  41. public String good()
  42. {
  43. String data = "root"; /* init data */
  44. String sKey = "sKey";
  45. Cipher cipher = null;
  46. try {
  47. SecretKeySpec key = new SecretKeySpec(sKey.getBytes(), "AES");
  48. cipher = Cipher.getInstance("AES"); // good 寮卞姞瀵�
  49. cipher.init(Cipher.DECRYPT_MODE, key);
  50. } catch ( NoSuchPaddingException e) {
  51. log.info("error");
  52. } catch (NoSuchAlgorithmException e) {
  53. log.info("error");
  54. } catch (InvalidKeyException e) {
  55. log.info("InvalidKeyException");
  56. }
  57. String pw = "";
  58. try {
  59. if(cipher != null){
  60. pw = new String(cipher.doFinal(data.getBytes()));
  61. }
  62. } catch (IllegalBlockSizeException e) {
  63. log.info("error");
  64. } catch (BadPaddingException e) {
  65. log.info("error");
  66. }
  67. String cipertext = pw;
  68. return cipertext;
  69. }
  70. }

No Description

Contributors (1)