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

How can we know the length of the key? #9

Open
KeithMorning opened this issue Jun 7, 2020 · 3 comments
Open

How can we know the length of the key? #9

KeithMorning opened this issue Jun 7, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@KeithMorning
Copy link

KeithMorning commented Jun 7, 2020

Great flutter RSA library! I have a question may be stupid... When we encrypt or decrypt a file lang than the key size, how can we know the length(128Bytes or 256Bytes) of the private key or public key? I didn't find this api in the library...

@jerson
Copy link
Owner

jerson commented Jun 7, 2020

HI @KeithMorning at this moment there is no method to obtain the information of the keys, I think it would be useful a method like this, I will investigate about it to see how it can be implemented in these days

note: if you create a key using the Generate method you'll know that value but it's probably not what you need

@jerson jerson added the enhancement New feature or request label May 20, 2021
@patachi
Copy link

patachi commented Dec 18, 2021

In most programming languages, the PrivateKey and PublicKey entity (class, struct, whatever it's called) usually have Size or Length property/field or something similar.

the key length can be either shown in bit(2048) or in Byte(2048/8 = 256)

the max length of the data that can be encrypted is calculated like this (all sizes are in Byte) :

max lenght for PKCS1v15 = publickKey.Size - 11
max length for OAEP = publicKey.Size - (hash.Size*2) - 2

for example, if we have RSA 2048 key we have:
size of RSA-2048 = 256
size of SHA265 = 32

for PKCS1v15 256 - 11 = 245
for OAEP 256 - (32*2) - 2 = 190

ref :
https://go.dev/src/crypto/rsa/pkcs1v15.go#L46
https://go.dev/src/crypto/rsa/rsa.go#L416

@jerson
Copy link
Owner

jerson commented Dec 18, 2021

Hi @patachi thanks for that, currently this method is implemented in rsa-mobile so we only need to include in flatbuffers and in dart
https://github.com/jerson/rsa-mobile/blob/master/rsa/metadata.go

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

No branches or pull requests

3 participants