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

Key Length issue #3

Closed
NTMS2017 opened this issue Jul 4, 2018 · 2 comments
Closed

Key Length issue #3

NTMS2017 opened this issue Jul 4, 2018 · 2 comments
Assignees
Labels
enhancement New feature or request question Further information is requested

Comments

@NTMS2017
Copy link

NTMS2017 commented Jul 4, 2018

First I use my key (Len:50) and I get below error. Error state that key must be 128/192 or 256bits.
I am confuse here. You have 32 character and its works.

https://stackoverflow.com/questions/4850241/how-many-bits-in-a-character has a explain that it depends what is the character and what encoding it is in. So do you going to support ISO-8895-1 tp ISO-8895-9 as well as, UTF-8, UTF-16, UTF-32 encoding type?

I will stick to 32 length now. My local language is TR and ISO-8895-5 (Latin-5 (Turkish)). It will be good to cover all other language. Thanks

Unhandled exception:
Invalid argument(s): Key length must be 128/192/256 bits
#0 AESFastEngine.init (package:pointycastle/block/aes_fast.dart:66:7)
#1 AES.encrypt (package:encrypt/src/aes.dart:20:9)
#2 Encrypter.encrypt (package:encrypt/encrypt.dart:17:17)
#3 main (file:///Users/niyazitoros/IdeaProjects/github/untitled/bin/main.dart:11:35)
#4 _startIsolate. (dart:isolate-patch/dart:isolate/isolate_patch.dart:279)
#5 _RawReceivePortImpl._handleMessage (dart:isolate-patch/dart:isolate/isolate_patch.dart:165)

@leocavalcante leocavalcante self-assigned this Jul 4, 2018
@leocavalcante leocavalcante added the question Further information is requested label Jul 4, 2018
@leocavalcante
Copy link
Owner

Hi @NTMS2017
This is a constraint of the algorithm: https://en.wikipedia.org/wiki/Advanced_Encryption_Standard
Keys must be 128, 192 or 256 bits, exactly this sizes, it's not a range.

As you researched, 1 utf-8 char is 4 bytes, so a 32 char length key is equals to 32 * 4 = 128 bits.

So keys should have:

UTF-8 length Bits
32 128
48 192
64 256

This can vary on the characters you are using

I highly recommend you to use a 256 bits key generated by a CSPRNG. PointyCastle has one, it is used for the Salts in password.

I will stick your issue to remember to add something like that in this project so you can generate cryptographic secure keys right from the terminal.

Note: You already able to do that thought /dev/urandom or RtlGenRandom.

@leocavalcante leocavalcante added the enhancement New feature or request label Jul 4, 2018
@NTMS2017
Copy link
Author

NTMS2017 commented Jul 4, 2018

Thanks Leo, check all this tomorrow.

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

No branches or pull requests

2 participants