From 5ef0d052d2df0bd492b1bad6da106f99f5591f69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AB=98=E7=BA=A7=E4=BA=91=E8=84=91=E7=A0=94=E5=8F=91?= =?UTF-8?q?=E5=B7=A5=E7=A8=8B=E5=B8=88?= <153692773@qq.com> Date: Tue, 14 Mar 2023 18:16:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20'test.java'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test.java | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 test.java diff --git a/test.java b/test.java new file mode 100644 index 0000000..68d0882 --- /dev/null +++ b/test.java @@ -0,0 +1,60 @@ +package Null_Password; + +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 Null_Password { + + static final Logger log = Logger.getLogger("logger"); + + public String bad() { + + String password = null; // bad null密码 + + return password; + } + + public String good() + { + String data = "key"; /* init data */ + + String sKey = "Skey"; + Cipher cipher = null; + String pw = ""; + try { + SecretKeySpec key = new SecretKeySpec(sKey.getBytes(), "AES"); + cipher = Cipher.getInstance("AES"); + cipher.init(Cipher.DECRYPT_MODE, key); + }catch (NoSuchPaddingException e) { + log.info("error"); + } catch (NoSuchAlgorithmException e) { + log.info("error"); + } catch (InvalidKeyException e) { + log.info("InvalidKeyException"); + } + + try { + if(cipher != null){ + pw = new String(cipher.doFinal(data.getBytes())); + } + + } catch (IllegalBlockSizeException e) { + log.info("error"); + } catch (BadPaddingException e) { + log.info("error"); + } + + String password = pw; // good null密码 + + return password; + + } + +} \ No newline at end of file