Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't decrypt iOS encrypte data in base64 format #1

Open
yasirIqbal11 opened this issue Jul 5, 2021 · 0 comments
Open

Can't decrypt iOS encrypte data in base64 format #1

yasirIqbal11 opened this issue Jul 5, 2021 · 0 comments

Comments

@yasirIqbal11
Copy link

yasirIqbal11 commented Jul 5, 2021

I am using BlueEcc for prime256v1 ecnryption and both in iOS and on Node.js server!
I encrypt data in iOS and pass it to Node.js server in base64 form. I am passing both base64 encrypted data and buffer data but receive error.
It doesn't decrypt data COMING FROM IOS SIDE, same for the other way.

I receive the following error!

nternal/crypto/cipher.js:172
const ret = this[kHandle].final();
^

Error: Unsupported state or unable to authenticate data
at Decipheriv.final (internal/crypto/cipher.js:172:29)
at Object.module.exports.decrypt (/Users/yasiriqbal/Desktop/encryption/index.js:114:62)
at Object. (/Users/yasiriqbal/Desktop/encryption/app.js:21:19)
at Module._compile (internal/modules/cjs/loader.js:1133:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
at Module.load (internal/modules/cjs/loader.js:977:32)
at Function.Module._load (internal/modules/cjs/loader.js:877:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
at internal/main/run_main_module.js:18:47

This is my server code!

const ecc = require('./index');
const ECKey = require("ec-key");

let privateKeyString = "-----BEGIN EC PRIVATE KEY-----\nMHcCAQEEILaJOS3gzq30ub5QL0R3RSDCAeds+HHXNwbtpeJbGPR9oAoGCCqGSM49\nAwEHoUQDQgAEBAGv/eKV+rRnPJEmdT7PIE3iTGityqzxn8lCqVQ+reVLtrc+3c0Q\n0eSP7V19XtDgnjYzzX48T39u64QZ8gpt9A==\n-----END EC PRIVATE KEY-----"
let privateKeyBuffer = Buffer.from( ecc.extractKeyData(privateKeyString, "pem", false), 'base64');

let publicKeyString = "-----BEGIN PUBLIC KEY-----\nMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEBAGv/eKV+rRnPJEmdT7PIE3iTGit\nyqzxn8lCqVQ+reVLtrc+3c0Q0eSP7V19XtDgnjYzzX48T39u64QZ8gpt9A==\n-----END PUBLIC KEY-----"
let publicKey = Buffer.from( ecc.extractKeyData(publicKeyString, "pem", false), 'base64');

/*
let input = "yasir iqbal"
let encData = ecc.encrypt(publicKey, input);
*/

let encData = "BFU+yKJUjrb9qXdp2jsj+RDqBZbehyBmieX8M4imHWcxy0FvtaynTWRJy8ijAKBMHZCwcbYyt6UsrwLfFXkSG8W+oVI9k6G9zE/6bu0n5Ezif/gs6UIiG39Vq3M="
let base8Buffer = Buffer.from(encData, "base64");

console.log("Enc Data: ", encData);

let decData = ecc.decrypt(privateKeyBuffer, base8Buffer);
console.log("Decrypt Data: ", decData);

Your help would be appreciated! Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant