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.

test.java 1.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package Null_Password;
  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 Null_Password {
  11. static final Logger log = Logger.getLogger("logger");
  12. public String bad() {
  13. String password = null; // bad null密码
  14. return password;
  15. }
  16. public String good()
  17. {
  18. String data = "key"; /* init data */
  19. String sKey = "Skey";
  20. Cipher cipher = null;
  21. String pw = "";
  22. try {
  23. SecretKeySpec key = new SecretKeySpec(sKey.getBytes(), "AES");
  24. cipher = Cipher.getInstance("AES");
  25. cipher.init(Cipher.DECRYPT_MODE, key);
  26. }catch (NoSuchPaddingException e) {
  27. log.info("error");
  28. } catch (NoSuchAlgorithmException e) {
  29. log.info("error");
  30. } catch (InvalidKeyException e) {
  31. log.info("InvalidKeyException");
  32. }
  33. try {
  34. if(cipher != null){
  35. pw = new String(cipher.doFinal(data.getBytes()));
  36. }
  37. } catch (IllegalBlockSizeException e) {
  38. log.info("error");
  39. } catch (BadPaddingException e) {
  40. log.info("error");
  41. }
  42. String password = pw; // good null密码
  43. return password;
  44. }
  45. }