Answer the question
In order to leave comments, you need to log in
R.S.A. Similar to nodejs?
In python, I get a hash with this series of commands:
>>> import rsa
>>> import base64
>>> from django.conf import settings
>>> with open(settings.KEY_FILE, 'rb') as keyf:
... priv_key = rsa.PrivateKey.load_pkcs1(keyf.read(), format='PEM')
...
>>> mess = 'var1=123\r\nvar=456\r\n'
>>> sign = rsa.sign(mess, priv_key, "SHA-1")
>>> import urllib
>>> from base64 import standard_b64encode
>>> b64sign = urllib.quote(standard_b64encode(sign), safe='')
>>> b64sign
const NodeRSA = require('node-rsa')
const urlencode = require('urlencode')
fs.readFile(config.keyFile, 'ascii', function (err,content) { // keyFile тот же что и в Python
if (err) {
return console.log('error ', err);
}
rsa_key = content
var my_hash = mess // mess такой же как в Python
var key = new NodeRSA(rsa_key, 'pkcs1-private-pem')
key.setOptions({signingScheme: 'pss-sha1'}) // тут перебирал все доступные варианты
my_hash = key.encryptPrivate(my_hash, 'base64')
console.log(urlencode(my_hash))
}
Answer the question
In order to leave comments, you need to log in
I solved the problem with this piece of code:
var out_ = windows1251.encode(out, {})
var signer = crypto.createSign('RSA-SHA1')
signer.update(out_)
var pem = fs.readFileSync(config.keyFile)
var rsa_key = pem.toString('ascii')
var res = signer.sign(rsa_key, 'base64')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question