小编Cur*_*mer的帖子

尝试使用私钥解密消息时出现node-rsa错误

所以我一直在尝试使用带有node-rsa的节点和带有jsencrypt的 javascript 来创建一个网站(用于分配),其中javascript客户端获取服务器生成的公钥(node-rsa),加密消息(jsencrypt)用户已输入,将其发送到服务器并让服务器对其进行解密(node-rsa).密钥的生成起作用,加密工作但解密不起作用.当我启动节点脚本时,我执行以下加密...

var NodeRSA = require('node-rsa');
var myDecrypter = new NodeRSA({b: 512});
Run Code Online (Sandbox Code Playgroud)

当客户端请求密钥(我使用快速)时,运行以下内容.

app.get('/getPublicKey', function(req, res){
    var publicKeyJson = {"Key": ""};
    console.log(myDecrypter.exportKey('public'));
    publicKeyJson.Key = myDecrypter.exportKey('public');
    res.json(JSON.stringify(publicKeyJson));
});
Run Code Online (Sandbox Code Playgroud)

然后客户端像这样保存该密钥......

var myEncrypter = new JSEncrypt();
var myJson  = "";
$.getJSON( "getPublicKey", function( data ) {
    myJson = JSON.parse(data).Key;
        setKey();
});
function setKey() {
    myEncrypter.setPublicKey(myJson);
}
Run Code Online (Sandbox Code Playgroud)

当我在客户端加密并发送消息时,我这样做......

function messageEncrypt() {
    message = document.getElementById("message").value;
    var encrypted = myEncrypter.encrypt(message);
    myMessage = {"username": "", "userId": 0.0, "message": ""};
    myMessage.username = me.username;
    myMessage.userId …
Run Code Online (Sandbox Code Playgroud)

javascript encryption cryptography node.js

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

即使'if'为真,也会执行其他语句

我一直在研究python脚本来检测按键.它使用pygame模块.我的问题是按下向上,向下和向右箭头键而不是左键.我已经看过这个,但它对我的问题没有帮助.问题是,当我按向上,向下或向右键时,它会打印相应的文本,然后执行else语句以及用这个奇怪的符号替换even.unicode,无论何时按下左箭头键,它都会打印出"键是左"而没有更多,就像它应该的那样.按下键盘上的任何普通键都可以正常工作.奇怪的HUH.如果你能发现我做过的嘘声真的很棒.我的代码在下面,如果安装了pygame,你可以将其复制并粘贴到2.7空闲状态,看看我的意思.

#Python key detector, requires pygame module, uses python 2.7
#Import libraries
import pygame
import sys
from pygame.locals import *
#Init display
pygame.display.init()
#Infinite loop
while (True):
    #Event detector
    for event in pygame.event.get():
        #If a key is pressed
        if event.type == KEYDOWN:
            if event.key == 99:
                sys.exit()
            if event.key == 273:
                print "The key is Up"
            if event.key == 275:
                print "The key is Right"
            if event.key == 274:
                print "The key is Down"
            if event.key == 276: …
Run Code Online (Sandbox Code Playgroud)

python

-3
推荐指数
1
解决办法
289
查看次数

标签 统计

cryptography ×1

encryption ×1

javascript ×1

node.js ×1

python ×1