3 回答

TA贡献2021条经验 获得超8个赞
public static byte[] encrypt(String toEncrypt) throws Exception{
方法名称是: 加密
它接收什么参数:一个名为 图恩密特
其访问修饰符: 公共静电
如果可能的话 抛出
调用时的异常。
.... concatURL = padString(concatURL, ' ', 16); byte[] encrypted = encrypt(concatURL); <-- HERE!!!!! String encryptedString = bytesToHex(encrypted); content.removeAll(); ......
public static byte[] encrypt(String toEncrypt) { try{ String plaintext = toEncrypt; String key = "01234567890abcde"; String iv = "fedcba9876543210"; SecretKeySpec keyspec = new SecretKeySpec(key.getBytes(), "AES"); IvParameterSpec ivspec = new IvParameterSpec(iv.getBytes()); Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding"); cipher.init(Cipher.ENCRYPT_MODE,keyspec,ivspec); byte[] encrypted = cipher.doFinal(toEncrypt.getBytes()); return encrypted; } catch ( NoSuchAlgorithmException nsae ) { // What can you do if the algorithm doesn't exists?? // this usually won't happen because you would test // your code before shipping. // So in this case is ok to transform to another kind throw new IllegalStateException( nsae ); } catch ( NoSuchPaddingException nspe ) { // What can you do when there is no such padding ( whatever that means ) ?? // I guess not much, in either case you won't be able to encrypt the given string throw new IllegalStateException( nsae ); } // line 109 won't say it needs a return anymore. }
try { // risky code ... } catch( Exception e ) { // a bomb has just exploited // you should NOT ignore it } // The code continues here, but what should it do???

TA贡献1864条经验 获得超2个赞
异常;必须捕获或声明为抛出字节[]加密=加密(串联URL);
encrypt
actionPerformed
你可以移除 throws Exception
从你的 encrypt
方法和 实际手柄
内部异常 encrypt
.可以从 encrypt
加上 throws Exception
的异常处理块 actionPerformed
方法。
encrypt
encrypt
添加回答
举报