-
-
Notifications
You must be signed in to change notification settings - Fork 42
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
Unsupported state or unable to authenticate data #29
Comments
I think the error is related to your code not passing 'hex' to the cypher.final(), like `cypher.final('hex') |
@AllanOricil so did you solve this at the end? I am getting same error message and researching for the fix. What was your solution? |
@o1dnik could not fix :/ |
@AllanOricil Do you know the value that was encrypted and is it something you can share here? Was the value encrypted using I can not seem to fail the encryption or decryption using the private key you have provided as the secret. The |
@MauriceButler I can get another message to encrypt and decrypt to you later today. I tested the encryption with Crypto-js and it also did not work. This lib and crypto-js only worked well for me when I used a simpler string as my key, like |
Try to decrypt the encrypted string with the key above. See if you can. You will probably have the same error as me. This cleary shows there is a limitation in the encryption. |
@MauriceButler here is a message to encrypt: this is the key: please, keep the blank line at the end of the key to keep the test consistent
|
So With the key and value you just provided, I can encrypt and decrypt the value correctly. Code for a test with a large secret below const largeSecret = `-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAtLUeYvKWtAzhgeCM/bdQrirG+1m1OyDgM5bJfzyOE0Qd7Zyb
IhLrJ/jQpuYQ3tqdwXJBozRLpj9S4zid7S75SF+bvPGU5QY9fhCxJYbyf8yaiQ+v
vIQf6cbhOYOKtm16rRdxX2wJj28ETx8SWmRgTkLGlDmGkiUSAWr/8QMWSYuCnG1c
470v3f/PvUC4XlohZWBPs2uZGUge27shKluclGwryojH6AaCr/h5fSjHBQxcChp2
Yp/Qx2QU5fVbQpZNZ2cvvGCCTJbu4CX381jL+T4twQa5JWPZC1u1sI/VvmEVCRto
VhcErP/lCRJk2Qcp1c4A+QFySb+l9HGkVwq3BwIDAQABAoIBADecJSW+EbKG5D7b
o4fQifuPHnzrNmJj05sMpCWLtQ0owS0GLJdnywYaA9vYoQhzrmiBiMF4rm8Svac/
HRqIgh5LjdmvXmq8aOAKsvkh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4RgzyO6xTL
UkecGtAgt9zQZ349rtyJjZz9ePCCkH/kTfUHXrxTjfhLyYVqlaJy
-----END RSA PRIVATE KEY-----
`;
const input = '5Aep861OVg8QiCb44ByDkG6vdPo8AkeO5Tgs9O7gGeOlF4jqpP_p8ibvCms_Vo.EXVhYN7wDfagTUsIBlhsNX9c';
const cryptr = new Cryptr(largeSecret);
const encryptedString = cryptr.encrypt(input);
console.log(encryptedString); // 'd9752e5656b27017a826db1902bae6b65f751600020ac8a77c23bbec2fde437bc97412859864364a8d71959b80f186f0fbc2bf2298043332fee74fb06d55b96a5ff6b0757d5708e3a00c52c537e08a9a0d6048d2eaae82a9fd858a83fe5bdc7ffb494564595d38b0193bdfc0e4142088db022681f39a66ef1c3d6705053c92906ecc80119ae18b69d6bda066edc9e7b156c788b7ae5922fc58b2e9504ed690786650e544579ec1761b2655eabd2a3a9bfe2c69eb36b5dd'
const decryptedString = cryptr.decrypt(encryptedString);
console.log(decryptedString); // '5Aep861OVg8QiCb44ByDkG6vdPo8AkeO5Tgs9O7gGeOlF4jqpP_p8ibvCms_Vo.EXVhYN7wDfagTUsIBlhsNX9c'
console.log(decryptedString === input); // true So I can not see a problem with value encrypted and decrypted with this library using a large secret like that. I agree that the value you provided in the initial report does not decrypt but I can't reproduce that from a value encrypted from this library. Can you confirm the above code works for you? If you can make it fail I am happy to have a look further but I cant see an issue at the moment. |
@MauriceButler I did this test and I also was able to do it in one round, like your code above. Do this: Also, you have to add an empty line in the key at the end. Could you also read the key from a file, like Im doing. DON'T FORGET TO ADD THE EMPTY LINE!!! const largeSecret = `-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAtLUeYvKWtAzhgeCM/bdQrirG+1m1OyDgM5bJfzyOE0Qd7Zyb
IhLrJ/jQpuYQ3tqdwXJBozRLpj9S4zid7S75SF+bvPGU5QY9fhCxJYbyf8yaiQ+v
vIQf6cbhOYOKtm16rRdxX2wJj28ETx8SWmRgTkLGlDmGkiUSAWr/8QMWSYu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OBSvfq/yVl5bJxUEf2F4jV36e1TQEtS9BUt
DRcgbxCMiDGDz12OMCbhjoImo0ogShUWfOKp81cv43DJ0Wl6gkYgaL/2snBMrgjq
d/gew5D5EYR3ALqXG6qcVKOqkLul27j6U3hJAz0q0xBRZN1nS84lzAyLXUt6Tpr0
cuZRAoGBAKb0s3EHlDlTfCV9XBhJxXMBpmTDBI7n9YswyVsjo83VS13Ux3NqGuVA
2vb7GdgEOWzAWne03I+A47b6EDCwVyduLCQ8UqKmda6xSbf93Vwzet4RgzyO6xTL
UkecGtAgt9zQZ349rtyJjZz9ePCCkH/kTfUHXrxTjfhLyYVqlaJy
-----END RSA PRIVATE KEY-----
`; |
Hi @AllanOricil I still am unable to break it. Only thing I can think of is the way you are either reading or writing values to disk or then converting them to UTF-8 is incorrect. If you can produce a failing example I am happy to keep looking into this but at this stage I cant find any issue. The below code writes and reads all data from disk. Still works correctly, even if done later and not in the same process. const fs = require('fs');
const key = `-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAtLUeYvKWtAzhgeCM/bdQrirG+1m1OyDgM5bJfzyOE0Qd7Zyb
IhLrJ/jQpuYQ3tqdwXJBozRLpj9S4zid7S75SF+bvPGU5QY9fhCxJYbyf8yaiQ+v
vIQf6cbhOYOKtm16rRdxX2wJj28ETx8SWmRgTkLGlDmGkiUSAWr/8QMWSYuCnG1c
470v3f/PvUC4XlohZWBPs2uZGUge27shKluclGwryojH6AaCr/h5fSjHBQxcChp2
Yp/Qx2QU5fVbQpZNZ2cvvGCCTJbu4CX381jL+T4twQa5JWPZC1u1sI/VvmEVCRto
VhcErP/lCRJk2Qcp1c4A+QFySb+l9HGkVwq3BwIDAQABAoIBADecJSW+EbKG5D7b
o4fQifuPHnzrNmJj05sMpCWLtQ0owS0GLJdnywYaA9vYoQhzrmiBiMF4rm8Svac/
HRqIgh5LjdmvXmq8aOAKsvkhdi7uAAB9207gOhHvKhBQ8rcBKedqd3EuBiMlvuW6
YiN/EEQFOKcUr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LyYVqlaJy
-----END RSA PRIVATE KEY-----
`;
fs.writeFileSync('./key.txt', key);
const largeSecret = fs.readFileSync('./key.txt', 'utf-8');
const cryptr = new Cryptr(largeSecret);
const originalInput = '5Aep861OVg8QiCb44ByDkG6vdPo8AkeO5Tgs9O7gGeOlF4jqpP_p8ibvCms_Vo.EXVhYN7wDfagTUsIBlhsNX9c';
fs.writeFileSync('./input.txt', originalInput);
const input = fs.readFileSync('./input.txt', 'utf-8');
const encryptedString = cryptr.encrypt(input);
fs.writeFileSync('./encrypted.txt', encryptedString);
const valueToDecrypt = fs.readFileSync('./encrypted.txt', 'utf-8');
const decryptedString = cryptr.decrypt(valueToDecrypt);
console.log(decryptedString === originalInput); // <-- true Here are the files I wrote to disk. |
@MauriceButler Hi, please, follow the steps bellow:
Obs: When I run the encryption and decryption in the same script, like you did in the last two attempts, I don't get any exceptions. It only happens when I run them separated. encrypt.js const fs = require('fs');
const Cryptr = require('cryptr');
const serverKey = fs.readFileSync('./server.txt', { encoding: 'utf-8' } );
const cryptr = new Cryptr(serverKey);
const encryptedMessage = cryptr.encrypt('5Aep861OVg8QiCb44ByDkG6vdPo8AkeO5Tgs9O7gGeOlF4jqpP_p8ibvCms_Vo.EXVhYN7wDfagTUsIBlhsNX9c');
console.log(encryptedMessage); decrypt.js const fs = require('fs');
const Cryptr = require('cryptr');
const serverKey = fs.readFileSync('./server.txt', { encoding: 'utf-8' } );
const cryptr = new Cryptr(serverKey);
const decryptedMessage = cryptr.decrypt(ENCRYPTED_MESSAGE);
console.log(decryptedMessage); |
Hi I was looking at this package to use as well, I tried your test to see if it works, but it works for me without any issues. I ran the encrypt and decrypt in a separate process and no problems at all. |
@michael-trinity publish this repo on github and share with me. I will run it without changing anything and see the results. I think it is weird, because the problem only happens when I separate the encryption and decryption in different processes. Also, @o1dnik reported the same error message. And we don't know what we might be doing wrong. |
As far as I can tell there is no problem with this module itself, but more with you saving / reading from disk. I am only guessing but something like different line endings could cause issues. I am going to close this issue now as there is nothing else I can assist with but please feel free to add anything you find to the issue for others who might have similar problems later on. |
same issue here |
Ok so i found the issue. Make sure your key size is max of 64bytes |
It failed for me when it was exactly 64 bytes! So do make sure it is less. Thanks @arnav7633 |
What am I doing with my life??? 3y passed and I'm still unhappy because people don't take me seriously. I told u this was not working. |
I can't decrypt this string. I encrypted a string with the following key, which I read from a file using fs and encoding utf-8. Then I tried to decrypt it and got the error in the image below.
My Key: attention, the key below has an empty line at the end
Encrypted String:
92df937f687b10f8c3c4ff6629bec84a0a5acfb9ba76243ee9d24e81a9b005394028740197f19aa27ccff3a373897f164c70837abf3eab0a193276a90a78ab2bbe636270df2809064f42ffbe1b3b066af627c3629d6bbb253f82b02434772065f3a552509fbbdbe7702c7c2dd5dc8e37fab94f00b62428e7df025e77f9bb0f9ebe0f830cd1ff39e4875d6c048efb856d3d224bb5db02d53b88bd7a14a6feb2a152e0c66a4eb4adf11f1b190a096a90e22a3a3cd4b64b5e
Error:
![image](https://user-images.githubusercontent.com/55927613/91673119-e4da5100-eb08-11ea-9bc0-297a53639e49.png)
The text was updated successfully, but these errors were encountered: