小编Jay*_*cee的帖子

如何在JavaScript中在1秒内完全执行1000次代码

n = 0;
var timer = setInterval(function() {
    if (n == 0) {
        console.log(new Date());
    }
    // execute some other code here
    n++;
    if (n == 1000) {
        clearInterval(timer);
        console.log(new Date());
    }
}, 1);
Run Code Online (Sandbox Code Playgroud)

此代码在大约3-4秒内执行,具体取决于机器和浏览器.如何让它在1秒内完成?

javascript loops setinterval

15
推荐指数
2
解决办法
1494
查看次数

"SHA1withRSA"的细节是什么?

无辜地,我认为"SHA1withRSA算法"只是用"SHA1"操作plainText,并使用RSA/pkcs1padding来加密"SHA1"的结果.但是,我发现我错了,直到我写了一些java代码来测试我的想法.我使用RSA publickey来解密签名,我使用相应的私钥来签署"SHA1withRSA算法".但我发现结果不等于"SHA1(plainText)",下面是我的java代码:

    String plaintext= "123456";
    Signature signature=Signature.getInstance("SHA1withRSA",new BouncyCastleProvider());
    signature.initSign(pemPrivatekey);
    signature.update(plaintext.getBytes());
    byte[] sign = signature.sign();
    //RSA decode
    byte[] bytes = RsaCipher.decryptByRsa(sign, pemPublickey);
    String rsaDecodeHex=Hex.toHexString(bytes);
    System.out.println(rsaDecodeHex.toLowerCase());

    String sha1Hex = Hash.getSha1(plaintext.getBytes());
    System.out.println(sha1Hex);
    //rsaDecodeHex!=sha1Hex
Run Code Online (Sandbox Code Playgroud)

很容易找到rsaDecodeHex!=sha1Hex,在哪里

rsaDecodeHex = 3021300906052b0e03021a050004147c4a8d09ca3762af61e59520943dc26494f8941b

sha1Hex = 7c4a8d09ca3762af61e59520943dc26494f8941b.

那么,"SHA1withRSA"的细节是什么?

java encryption sha1 rsa digital-signature

1
推荐指数
1
解决办法
7441
查看次数

单击后禁用JButton并在完成任务后启用它

我有一个带有actionListener的JButton,当我多次点击它时,它会像我点击一样多次完成它的工作,下面是我的代码:

   mouseListener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
                JButton source = (JButton) e.getSource();
                source.setEnabled(false);
                try {
                    RequestCommon.ctbCookie = jtf.getText();
                    System.out.println( RequestCommon.ctbCookie );
                    HttpURLConnection connection = HttpURLConnectionBuilder.getConnection(RequestCommon.login, RequestCommon.getCtb888Headers());
                    String connectionOuput = HttpURLConnectionBuilder.getConnectionOuput(connection);
                    System.out.println(connectionOuput);
                    new Player(new BufferedInputStream(new FileInputStream(new File("sounds/8.mp3")))).play();
                } catch (IOException e1) {
                    e1.printStackTrace();
                } catch (JavaLayerException e1) {
                    e1.printStackTrace();
                }
                source.setEnabled(true);
        }
    };
    jb1.addActionListener(mouseListener);
Run Code Online (Sandbox Code Playgroud)

我希望无论我在作业运行期间点击多少次,它都不会再次执行.当工作完成后,如果我再次点击,工作将再次运行.我不知道该怎么做,请告诉我你是否知道,谢谢!

java swing

1
推荐指数
1
解决办法
992
查看次数

为什么Java泛型不能用于静态方法?

正如标题所述,为什么Java泛型不能用于静态方法? 在此输入图像描述

java generics static compiler-errors

-2
推荐指数
1
解决办法
41
查看次数