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

WebCrypto DOMException with RSA encrypt method #29

Closed
stanvladut opened this issue Apr 24, 2016 · 2 comments
Closed

WebCrypto DOMException with RSA encrypt method #29

stanvladut opened this issue Apr 24, 2016 · 2 comments

Comments

@stanvladut
Copy link

stanvladut commented Apr 24, 2016

Having the following code I can encrypt a small text file with some small text in it, but when I try with a 1MB text file I get DOMException.

I tried with the same files and even bigger ones with AES and everything worked well. Is there a limit of a file that can be encrypted with RSA-OAEP encrypt method?

var encryptFile = function(keyPair, file) {
var vector = crypto.getRandomValues(new Uint8Array(16));
window.crypto.subtle.encrypt(
{
name: "RSA-OAEP",
iv: vector
//label: Uint8Array([...]) //optional
},
keyPair.publicKey, //from generateKey or importKey above
file//ArrayBuffer of the data
)
.then(function(encrypted){
//returns an ArrayBuffer containing the decrypted data
console.log(encrypted);
})
.catch(function(err){
console.error(err);
});
};

@vibornoff
Copy link
Contributor

Is there a limit of a file that can be encrypted with RSA-OAEP encrypt method?

RFC-3447, paragraph 7.1.1 says

message <...>, an octet string of length mLen, where mLen <= k - 2hLen - 2

where k, hLen are:

k denotes the length in octets of the RSA modulus n
hLen — output length in octets of hash function

@stanvladut
Copy link
Author

Thank you so much, you are a life saver!! Sorry for my superficiality

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

2 participants