You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For my use case, i want to encrypt the string in javascript while string decryption will happen on server side (Flask based application).
I am using the below function. However, if the string is encrypted like this, the returned value is a string and not a bytes object that private key expects.
Below is the code that i am using for encoding after extracting the modulus and exponent from public key in python
async function encryptWithPublicKey(modulusB64, exponentB64, data) {
// Decode base64 strings to bytes
function base64ToHex(str) {
var raw = atob(str);
var result = '';
for (var i = 0; i < raw.length; i++) {
var hex = raw.charCodeAt(i).toString(16);
result += (hex.length === 2 ? hex : '0' + hex);
}
return result.toUpperCase();
}
// Decode base64 to hexadecimal
var modulusHex = base64ToHex(modulusB64);
var exponentHex = base64ToHex(exponentB64);
// Create RSAKey object and set public key
var rsa = new RSAKey();
rsa.setPublic(modulusHex, exponentHex);
console.log("set public key" + rsa);
var encrypted = rsa.encrypt(data);
return encrypted;
}
the return value encrypted is passed to private key decrypt
key_private[0].decrypt(encrypted_text_hsm)
However, i am getting
<_cython_3_0_10.generator object at 0x0000025EC04F2EF0>
how to address this issue?
The text was updated successfully, but these errors were encountered:
biyani701
changed the title
python-pkc11 with javascript
python-pkc11 with javascript + flask
Jul 8, 2024
For my use case, i want to encrypt the string in javascript while string decryption will happen on server side (Flask based application).
I am using the below function. However, if the string is encrypted like this, the returned value is a string and not a bytes object that private key expects.
Below is the code that i am using for encoding after extracting the modulus and exponent from public key in python
modulusB64 = base64.b64encode(public_key[Attribute.MODULUS]).decode('utf-8')
exponentB64 = base64.b64encode(public_key[Attribute.PUBLIC_EXPONENT]).decode('utf-8')
These are passed to javascript.
async function encryptWithPublicKey(modulusB64, exponentB64, data) {
// Decode base64 strings to bytes
function base64ToHex(str) {
var raw = atob(str);
var result = '';
for (var i = 0; i < raw.length; i++) {
var hex = raw.charCodeAt(i).toString(16);
result += (hex.length === 2 ? hex : '0' + hex);
}
return result.toUpperCase();
}
the return value encrypted is passed to private key decrypt
key_private[0].decrypt(encrypted_text_hsm)
However, i am getting
<_cython_3_0_10.generator object at 0x0000025EC04F2EF0>
how to address this issue?
The text was updated successfully, but these errors were encountered: