Giter VIP home page Giter VIP logo

steel_crypt's People

Contributors

akushwarrior avatar kevmoo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

steel_crypt's Issues

Hash SHA-1 not calculating right value

  String type = "SHA-1";
  Uint8List hash = Digest(type).process(Uint8List.fromList([0, 0, 0, 0, 0, 0, 0, 0]));

  print('$hash');

Version: 1.6.1

Expected: [5, 254, 64, 87, 83, 22, 111, 18, 85, 89, 231, 201, 172, 85, 134, 84, 241, 7, 199, 233]

Actual: [9, 62, 67, 119, 176, 114, 197, 97, 221, 184, 28, 162, 131, 250, 208, 153, 50, 219, 150, 148]

The SHA-1 hash is used as a checksum and the calculated checksum from this library is different to the one calculated by MessageDigest on android and pointycastle 1.0.2.

Load .pem from assets

How would you load a .pem file to use for asymmetric encryption from the assets directory?

Questions about ebc

`dart
var FortunaKey = 'qHjzUlcH02Q0zupxOSPPVQoY-LBI8Cmf4WoUNhw90B4==';

var aesEncrypter = AesCrypt(FortunaKey, 'ecb');

String encrypted = aesEncrypter.encrypt('1234567890', 'YueITUmQ0JBjH8==');

print(encrypted);
`

log Unhandled exception: type 'ParametersWithIV<KeyParameter>' is not a subtype of type 'KeyParameter' of 'params' #0 AESFastEngine.init (package:steel_crypt/PointyCastleN/block/aes_fast.dart) #1 ECBBlockCipher.init (package:steel_crypt/PointyCastleN/block/modes/ecb.dart:37:23) #2 PaddedBlockCipherImpl.init (package:steel_crypt/PointyCastleN/padded_block_cipher/padded_block_cipher_impl.dart:43:12) #3 AesCrypt.encrypt (package:steel_crypt/src/aes.dart:67:15) #4 main (test.dart:22:34) #5 _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:303:32) #6 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:12)

RegistryFactoryException: No algorithm registered of type BlockCipher with name: AES/OFB

Using v2.0.0, I was using this code to encrypt / decrypt a string :

String encryptionKey = await CryptKey().genFortuna();
String initializationVector = await CryptKey().genDart();
AesCrypt crypter = AesCrypt(
  key: encryptionKey,
  mode: ModeAES.ofb64,
  padding: PaddingAES.pkcs7,
);

String crypted = crypter.encrypt('string', iv: initializationVector)
String decrypted = crypter.decrypt(crypted, iv: initializationVector)

I recently upgraded to the latest version (2.2.1) and so I migrated the above code to :

String encryptionKey = await CryptKey().genFortuna();
String initializationVector = await CryptKey().genDart();
AesCrypt crypter = AesCrypt(
  key: encryptionKey,
  padding: PaddingAES.pkcs7,
);

String crypted = crypter.ofb64.encrypt(inp: 'string', iv: initializationVector)
String decrypted = crypter.ofb64.decrypt(enc: crypted, iv: initializationVector)

And now I get the following errors :

RegistryFactoryException: No algorithm registered of type BlockCipher with name: AES/OFB
#0      _RegistryImpl._createConstructor (package:pc_steelcrypt/src/registry/registry.dart:135:5)
#1      _RegistryImpl.getConstructor (package:pc_steelcrypt/src/registry/registry.dart:106:21)
#2      _RegistryImpl.create (package:pc_steelcrypt/src/registry/registry.dart:96:23)
#3      new BlockCipher (package:pc_steelcrypt/src/api/block_cipher.dart:9:16)
#4      PaddedBlockCipherImpl.FACTORY_CONFIG.<anonymous closure>.<anonymous closure> (package:pc_steelcrypt/padded_block_cipher/padded_block_cipher_impl.dart
#5      _RegistryImpl.create (package:pc_steelcrypt/src/registry/registry.dart:97:29)
#6      new PaddedBlockCipher (package:pc_steelcrypt/src/api/padded_block_cipher.dart:23:16)
#7      OfbSatellite.encrypt (package:steel_crypt/src/satellites/ofb.dart:18:11)
RegistryFactoryException: No algorithm registered of type BlockCipher with name: AES/OFB
#0      _RegistryImpl._createConstructor (package:pc_steelcrypt/src/registry/registry.dart:135:5)
#1      _RegistryImpl.getConstructor (package:pc_steelcrypt/src/registry/registry.dart:106:21)
#2      _RegistryImpl.create (package:pc_steelcrypt/src/registry/registry.dart:96:23)
#3      new BlockCipher (package:pc_steelcrypt/src/api/block_cipher.dart:9:16)
#4      PaddedBlockCipherImpl.FACTORY_CONFIG.<anonymous closure>.<anonymous closure> (package:pc_steelcrypt/padded_block_cipher/padded_block_cipher_impl.dart:18:
#5      _RegistryImpl.create (package:pc_steelcrypt/src/registry/registry.dart:97:29)
#6      new PaddedBlockCipher (package:pc_steelcrypt/src/api/padded_block_cipher.dart:23:16)
#7      OfbSatellite.decrypt (package:steel_crypt/src/satellites/ofb.dart:34:11)

Have I done something wrong ?

Why random key pair is generated on instantiation?

I come up with another issue, which I cannot really explain.

Is there any specific reason why each time an instance of RsaCrypt is created, it generates a new random key pair? It takes time and hardware computing power to do that, but why waste these precious resources if this random key pair is not needed at all?

I think that it’ll make more sense to move this task to a separate method, which could be called when and if required.

It's "insecure"

Not "UNSECURE". I looked this up to see if there was anything to recommend for Dart / RSA-OAEP, but if the homepage is spelling "UNSECURE" then I just assume that the programming is not mature.

"The statement, "The system we were testing was determined to be unsecured," would mean that the security was disabled, not that it was deficient."

Trying to encryption/decryption data using NodeJs Fails

Hi I am trying to replicate the same encryption/decryption that is done using Steel Crypt on NodeJs, the same data that is being encrypted on device needs to be decrypted on our server. But using the key to decrypt the data doesn't seem to work.

var aesEncrypter = AesCrypt(padding: PaddingAES.iso78164, key: secureKey);
      var encrypted = aesEncrypter.gcm.encrypt(inp: data, iv: salt);

this is encryption standard I am using.

Issue with communication between Dart-Java

I also encountered a communication encryption problem between Java and fluent in Java. AES/CFB/NoPadding is used in Java, and I can't use the nopadding of CFB to fill in in steel_crypt!

Originally posted by @cailetech in #11 (comment)

why key must 32-bits,I see java 16 bits, AES ECB

[ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: RangeError (start): Invalid value: Only valid value is 0: -16
E/flutter (10664): #0 RangeError.checkValidRange (dart:core/errors.dart:328:7)
E/flutter (10664): #1 _TypedIntListMixin.sublist (dart:typed_data-patch/typed_data_patch.dart:460:22)
E/flutter (10664): #2 PaddedBlockCipherImpl.doFinal (package:steel_crypt/PointyCastleN/padded_block_cipher/padded_block_cipher_impl.dart:95:64)
E/flutter (10664): #3 PaddedBlockCipherImpl.process (package:steel_crypt/PointyCastleN/padded_block_cipher/padded_block_cipher_impl.dart:82:25)

Get iv automatically

In PHP I use open_ssl to encrypt a file with AES256 CBC and the PKCS7 Padding.
The function automatically puts the iv on the start of the file for each block. Is there a way to get it automatically on the dart side?

In total there can be like 20 iv's or so.
How do I make your function AesCrypt.decrypt get automatically the iv for each block?

How to decrypt aes-256-gcm in PHP OpenSSL?

When I encrypt or decrypt aes-256-gcm in PHP OpenSSL, I will use tag, like this:

openssl_encrypt($input, 'aes-256-gcm', $key, OPENSSL_ZERO_PADDING, $iv,$tag);

And the tag parameter is required.

How can I get a tag in steel_crypt?

@AKushWarrior

Decrypting using either RSAKeys

Hello,

Looking through the documentation and examples, I can't find a way of decrypting an RSA encrypted message with someone's public key, since the decrypt function specifically specifies RSAPrivateKey. This function would be useful for when implementing end-to-end encryption where the sender encrypts with their private key, and the other receiver decrypts with the sender's public key. Is it possible for you to implement this feature? And hopefully also on the encryption function as well so it supports encrypting/decrypting with both RSAPublicKey and RSAPrivateKey.

Thanks!

Edit: I just made my own function to do this, so no need to rush this

Is it possible to have only the public key?

I think I am missing something, so enjoy a casual "I'm sorry, but" ... I'm kinda new to encrypting and this is my last straw.
So: is it possible to have only the public key in my dart code, because I only want to encrypt here - the private key should be placed somewhere in my backend.

Also, is it possible to read the keys from somewhere? I can only get the 'Instance of RSAPublicKey' and the API does not give me any information on how to do that.

I've read that you are busy, I'd feel honored if you come back to me about this!

Redesign steel_crypt API with a host of new features (steel_crypt 2.0)

This message has been hijacked to tell you that this issue is not just about the below. Instead,
it's an issue for Steel Crypt 2.0, a comprehensive revamp of steel_crypt which factors in user feedback. If you have something to add, comment at the very end. Otherwise, monitor the project board and #22 (comment) for progress on the TODO's.


Original Text:

Several areas of the package use strings to determine what type of encryption, padding, etc. to use. Although each possibility is well documented I wonder if it would be more user-friendly to provide these values as enums, or perhaps named constructors?

For example, we could go from:

final aesCbc = AesCrypt('cbc');

to

final aesCbc = AesCrypt(AesMode.cbc);

OR

final aesCbc = AesCrypt.cbc(otherParams);

As a new user of this plugin I'm willing to make these changes but I wanted to know your thoughts before starting the work.

Why enforcing base64 encoding?

First of all, thanks for taking time to write your awesome library!

I’m a bit puzzled with the fact that all hashing methods in the library return base64-encoded strings. So in fact instead of returning plain hashes, these methods return encoded hashes, and this doesn’t seem to be documented.

This is especially misleading when using password hashing methods, for which a hash length could be specified, but which return a value of different length (because of encoding), so to get the actual hash value, a base64-decoding of the returned value must be performed.

Could you please make base-64 encoding optional, maybe by adding a boolean argument to the existing hashing methods?

How to decrypt in PHP and OpenSSL?

Hi,

I totally no idea how to decrypt it in PHP and shell based OpenSSL.

Attempted to decrypt, but nothing to be print out.. Means maybe mode, IV or key is different....

Meanwhile, how to encrypt it with AES-256? It looks like not support aes-256-cbc

This is my PHP code :

openssl_decrypt(base64_decode("5hg/Q7t65Oa0uPZAKC5GJZ6JGFGvrKJzJOkNtxgkLm0="), $aes_mode, $key, OPENSSL_RAW_DATA, base64_decode($IV));

Thank you.

Regards,

Gordon

Password Hashing "Collisions" when using SHA-256/HMAC/PBKDF2

The following code using SHA-256/HMAC/PBKDF2 yielded colliding hashes when the input password did only have a one character difference (see example).
I am no cryptography expert, but I suspect this is not correct behavior. No collisions happened after changing the algorithm (tested with scrypt, SHA-384/HMAC/PBKDF2, SHA-512/HMAC/PBKDF2, SHA-3/256/HMAC/PBKDF2).

Example Code:

final passCrypt = PassCrypt("SHA-256/HMAC/PBKDF2");
final String salt = CryptKey().genDart(16);
final String pw1 = "12345";
final String pw2 = "12344";
final String pw3 = "12346";
final String pw4 = "12445";
final String pw5 = "12333";
final String hashed1 = passCrypt.hashPass(salt, pw1);
final String hashed2 = passCrypt.hashPass(salt, pw2);
final String hashed3 = passCrypt.hashPass(salt, pw3);
final String hashed4 = passCrypt.hashPass(salt, pw4);
final String hashed5 = passCrypt.hashPass(salt, pw5);
print("salt $salt");
print("hash1 $hashed1");
print("hash2 $hashed2");
print("hash3 $hashed3");
print("hash4 $hashed4");
print("hash5 $hashed5");

Outputs:

I/flutter (16996): salt nM6EwNuaWSptCcN6CHTgdw==
I/flutter (16996): hash1 22z1TmXCU/RzTts93APisjhJJ+wWtHXP0CnD/PqVHYA=
I/flutter (16996): hash2 22z1TmXCU/RzTts93APisjhJJ+wWtHXP0CnD/PqVHYA=
I/flutter (16996): hash3 22z1TmXCU/RzTts93APisjhJJ+wWtHXP0CnD/PqVHYA=
I/flutter (16996): hash4 22z1TmXCU/RzTts93APisjhJJ+wWtHXP0CnD/PqVHYA=
I/flutter (16996): hash5 ix0UCXAa7+uPYLNroeTZh7RinNq2Ou4GAns1FBVDddg=

The test was done on a physical android device with flutter. I did not test if this can be reproduced on another platform.

ASP.NET Core Identity PBKDF2

Hello.

I was wondering if you could help me. If you already have a hashed password done via ASP.NET Core Identity (PasswordHasher), is it possible to use this library to check the password hash against a plain text password?

I have tried to use PassCrypt with SHA-256 HMAC ('SHA-256/HMAC/PBKDF2') using the checkPassKey method but it does not work. Obviously it's fine if I generate the hash with this library and check it, however I need to authenticate already registered hashes.

The back-end uses this below:
ASP.NET Core Identity Version 3: PBKDF2 with HMAC-SHA256, 128-bit salt, 256-bit subkey, 10000 iterations

My knowledge of this isn't great hence why I'm asking for some help as to why it doesn't work. Any help would be much appreciated.

Thanks

Speed

Hi,
First I want to say thanks so much for your library, it has made me life so much easier and is much more stable than any of the other libraries I have tried. I was just wondering if there was anyway of increasing the speed of encryption, I am building a desktop application that is required to encrypt files (up to 1GB) and currently using the library for a 50 mb file takes a tad over a minute which is significantly longer than something like GPG. Is there anyway of speeding this up? My current encryption line is as follows using a 32 byte key

  var result = await aes.gcm.encrypt(inp: base64Encode(message), iv: iv16);

Thanks

AES 128 ECB No Padding

Hi @AKushWarrior ,
Thanks for this great package. I am trying to communicate with my MiBand using Bluetooth and the authorization requires to encrpyt a key with "AES/ECB/NoPadding". However in your wiki, it says:

5 paddings available for block modes:

PKCS7 Padding ('pkcs7') (Default)
ISO7816-4 Padding ('iso7816-4')
X9.23 Padding ('x9.23')
TBC Padding ('tbc')
ISO10126-2 Padding ('iso10126-2')
Note: All block modes require padding, to ensure that input is the correct block size.

Note: Paddings do not work with stream modes. You can still enter the parameter, but it won't be used.

Does any of those 5 padding options correspond to "No Padding"?
If not, Are you planning on supporting that mode?
Or it says paddings don't work in stream modes. I am not sure what it exactly is. But if I use stream mode, does that mean it will be like no padding?

SHA3 SHAKE

Great Lib! Thank you very much!

What about adding SHAKE on your roadmap?

Does this package allows AES-GCM or ChaCha20Poly1305 streaming?

I've actually just asked similar question: dint-dev/cryptography#125 (cryptography package for Flutter), but since this package uses PointyCastle there is a chance things may be different.

Basically, I am looking to decrypt the AES-GCM stream on the fly and still perform the authentication after the whole stream is read. Is that possible with this library?
Whilst it has certain security risks, it is certainly possible from a protocol perspective (see example Python code: https://trinket.io/python3/445dfc8d86 - sometimes run button needs to be clicked couple times for the "crypto" imports to be loaded correctly)

Second question is how does one go about encrypting big file, e.g. 10GB video (which is perfectly fine from an AES-GCM security perspective, as way <64GB limit) without facing any memory issues?

If it turns out be difficult to achieve streaming with the current state of Dart libraries, I would consider switching to different cipher, since I have flexibility to decide at this point.
I've noticed that whereas GCMBlockCipher extends BaseAEADBlockCipher, the ChaCha20Poly1305 extends BaseAEADCipher which has additional doFinal method which I hope brings me closer to performing encryption/decryption in chunks and then running verification/authentication at the end.

Can you help me to identify if there are any ways to achieve streaming using any authenticated protocol whether AES or ChaCha20?

Encrypt and Decrypt MD5?

final encrypter = HashCrypt('MD5');
final result = encrypter.hash('123');
duvida

final encrypter = HashCrypt('MD5');
final encodeResult = encrypter.hash('1234');

duvida2

I need to decode the generated hash.

final decodeResult = encrypter.decodehash("2FoqAjj0eOGRjccTlMQZEg==");

result => 1234

Publish package

Hi, can you publish your latest version with the new dependencies, we're hitting a dependency issue because of it. Thanks

How to use AES mode ECB with ZeroPadding

Hello,
I have this code in JavaScript:

encode(text, key) {
  let cipher = CryptoJS.enc.Utf8.parse(text);
  let flags = CryptoJS.enc.Utf8.parse('');

  let result = CryptoJS.AES.encrypt(key, cipher, { iv: flags, mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.ZeroPadding });
  return result.toString();
}

I need to run in DART but this package does not have ZeroPadding, anyone can help me?

Password-based AES CBC encryption?

There are few encryption library available for Flutter but this look more reliable library because of documentation or simpleness.
The key and ivsalt are generate randomly each time, how can I achieve the password-based encryption?
I'm not familiar with crypto, maybe is AES/CBC/PKCS5PADDING?

Flutter web build fails when including any version of steel crypt.

Hello, I have encountered an issue when trying the flutter build web command and including any version of steel crypt(Specifically tried with 2.2.1 and 1.6.1) in the pubspec, even if it isn't used anywhere.

image

Simply running a web server works without issues.

These are other dependencies , that I have included in my project if that helps.

image

encrypt and decrypt data between python crypto package and dart steel_crypt

hi
thank for your great package,
i need to encrypt and decrypt data between client(dart) and server(python)
can you give me a tutorial for encrypt and decrypt data from aes-ctr in dart ,
in python i use Cryptodome package

python code

class MyCryptoData(object):

    def __init__(self, key):
        # encode key from string, and 16 byte==> 16 character like "backtorealityman"
        self.key = key.encode('utf-8')

    # encrypt data
    def encrypt_data(self, data):
        # crate new cipher with CTR mode
        cipher = AES.new(self.key, AES.MODE_CTR)
        # encrypt data with utf-8 encoding
        ct_bytes = cipher.encrypt(data.encode('utf-8'))
        # get nonce from created cipher and encode to base64 from utf8 decoding
        nonce = base64.b64encode(cipher.nonce).decode('utf-8')
        # convert encrypted file in base64 and decode from utf-8
        ct = base64.b64encode(ct_bytes).decode('utf-8')
        # save base64 nonce  and base64 encrypted file in json and return this file
        return json.dumps({'nonce': nonce, 'data': ct})

    def decrypt_data(self, data):
        # load encrypted data from json, nonce and encrypted file
        b64 = json.loads(data)
        # nonce from json
        nonce = base64.b64decode(b64['nonce'])
        # encrypted data from json
        ct = base64.b64decode(b64['data'])
        # decrypted with key, nonce and current mode CTR
        cipher = AES.new(self.key, AES.MODE_CTR, nonce=nonce)
        # its done, data encrypted and decrypted correct
        return cipher.decrypt(ct)


Feature suggestion: encode AES key.

I couldn't find a method to encode AES key to store it as a string. Is it possible to add this? I would like to be able to store AES key in my database.

When encrypting on windows and decrypting on linux, something went wrong

I do n’t know why this happens, can someone help me?

On Win

  var publicKeyFile = File('D:\\Web\\api_test\\files\\rsa_public_key.pem');

  var publicStr = await publicKeyFile.readAsString();
  publicKey = rsaC.parseKeyFromString(publicStr);
 
  var eData = rsaC.encrypt('123456789', publicKey);
  var result = await Dio().post(url, data: {'data': eData});
  print(result);

On Linux

    final RsaCrypt rsaC = RsaCrypt();
    RSAPrivateKey rsaPrivateKek;

    final pemFile =
        File('/var/www/lingyun_server/keys/rsa_private_key_pkcs8.pem');
    final str = await pemFile.readAsString();
    rsaPrivateKeyWk = rsaC.parseKeyFromString(str)
    // data is passed by post (application/json) request
    print(rsaC.decrypt(data.eData, rsaPrivateKeyWk));
 
[SEVERE] aqueduct: POST /toolspack/sead 7ms 500 {user-agent : Dart/2.7 (dart:io)\ncontent-type : application/json; charset=utf-8\nconnection : close\naccept-encoding : gzip\ncontent-length : 201\nhost : 127.0.0.1:8888\n}  Invalid argument(s): data wrong #0      OAEPEncoding._decodeBlock (package:steel_crypt/PointyCastleN/asymmetric/oaep.dart:232:7)
#1      OAEPEncoding.processBlock (package:steel_crypt/PointyCastleN/asymmetric/oaep.dart:107:14)
#2      BaseAsymmetricBlockCipher.process (package:steel_crypt/PointyCastleN/src/impl/base_asymmetric_block_cipher.dart:21:15)
#3      RsaCrypt.decrypt (package:steel_crypt/src/rsa.dart:148:27)
#4      ToolsPackController.getEnterAppData (package:lingyun_server/controller/tools_pack_controller.dart:106:16)
#5      ToolsPackController.httpPost (package:lingyun_server/controller/tools_pack_controller.dart:68:14)
#6      _InstanceMirror._invoke (dart:mirrors-patch/mirrors_impl.dart:327:37)
#7      _InstanceMirror.invoke (dart:mirrors-patch/mirrors_impl.dart:323:25)
#8      BoundOperation.invoke (package:aqueduct/src/http/resource_controller_internal/controller.dart:24:10)
#9      ResourceController._process (package:aqueduct/src/http/resource_controller.dart:371:36)

#10     ResourceController.handle (package:aqueduct/src/http/resource_controller.dart:138:14)

#11     Controller.receive (package:aqueduct/src/http/controller.dart:174:30)
#12     _ControllerRecycler.receive (package:aqueduct/src/http/controller.dart:402:17)
#13     Controller.receive (package:aqueduct/src/http/controller.dart:206:28)

#14     Router.receive (package:aqueduct/src/http/router.dart:139:18)
#15     _RootZone.runUnaryGuarded (dart:async/zone.dart:1316:10)
#16     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:338:11)
#17     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:265:7)
#18     _ForwardingStreamSubscription._add (dart:async/stream_pipe.dart:134:11)
#19     _MapStream._handleData (dart:async/stream_pipe.dart:234:10)
#20     _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:166:13)
#21     _RootZone.runUnaryGuarded (dart:async/zone.dart:1316:10)
#22     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:338:11)
#23     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:265:7)
#24     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:766:19)
#25     _StreamController._add (dart:async/stream_controller.dart:642:7)
#26     _StreamController.add (dart:async/stream_controller.dart:588:5)
#27     _HttpServer._handleRequest (dart:_http/http_impl.dart:2828:19)
#28     new _HttpConnection. (dart:_http/http_impl.dart:2586:19)
#29     _RootZone.runUnaryGuarded (dart:async/zone.dart:1316:10)
#30     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:338:11)
#31     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:265:7)
#32     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:766:19)
#33     _StreamController._add (dart:async/stream_controller.dart:642:7)
#34     _StreamController.add (dart:async/stream_controller.dart:588:5)
#35     _HttpParser._headersEnd (dart:_http/http_parser.dart:388:17)
#36     _HttpParser._doParse (dart:_http/http_parser.dart:703:15)
#37     _HttpParser._parse (dart:_http/http_parser.dart:320:7)
#38     _HttpParser._onData (dart:_http/http_parser.dart:812:5)
#39     _RootZone.runUnaryGuarded (dart:async/zone.dart:1316:10)
#40     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:338:11)
#41     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:265:7)
#42     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:766:19)
#43     _StreamController._add (dart:async/stream_controller.dart:642:7)
#44     _StreamController.add (dart:async/stream_controller.dart:588:5)
#45     _Socket._onData (dart:io-patch/socket_patch.dart:1831:41)
#46     _RootZone.runUnaryGuarded (dart:async/zone.dart:1316:10)
#47     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:338:11)
#48     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:265:7)
#49     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:766:19)
#50     _StreamController._add (dart:async/stream_controller.dart:642:7)
#51     _StreamController.add (dart:async/stream_controller.dart:588:5)
#52     new _RawSocket. (dart:io-patch/socket_patch.dart:1379:33)
#53     _NativeSocket.issueReadEvent.issue (dart:io-patch/socket_patch.dart:899:14)
#54     _microtaskLoop (dart:async/schedule_microtask.dart:43:21)
#55     _startMicrotaskLoop (dart:async/schedule_microtask.dart:52:5)
#56     _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:118:13)
#57     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:175:5)

RSACrypt Invalid argument(s): Input data too large

I'm trying to encrypt a string, it's not very long and I'm getting an Input Data Too large error.

`
final String ENC_TEST_DATA = '''
sdsgasfgfsghasjghsjdghkjshgkjasdhgksadhgjksdhgkjsdhgkjsdhgkjshgkshgksfhgjkfshgjkshfgkjhfsgafsgsafghfsjgs
fgjjghkjasfghkjashgkjashgkjshgkjshgjkshgkjshgkjshgkjashgkjhasgkjhasfkgjhasfjkghasfkjghfsakjghasfkjghfsgfsg
ahsgkjhsfjkghsfkjghkjsfghkjsfgasgafsgaskjghkjsahgkjshgkjshgkjshgkjshgksgsg
sghskdjhgkjsdhgksdhgkashgkshgkhasgkjdshgkjhsdgkjhwiutwuituwighkjfhgkjashowetoojashgjksdahgkjshgkjshg
gsdgjshgjksdhgjsdhgkjsdhgjksdhkjghsdkjghsdkjgsdkjhgkjsdhgkjsdhgjksdhgkjdshgkjsdgjksdhgkjhsdkgjhdskjgsdgksjdhgsd
sgjsdakgjhsakjghaskjghaskjghsakjghkjadshgkjsadhgkjwehoutewuuweghwjkghewuosdghsdjhgoeureoghsjkghkjsd
''';

final String ENC_TEST_DATA_BOB = ENC_TEST_DATA+"FOR BOB";
final String ENC_TEST_DATA_SUZIE = ENC_TEST_DATA+"FOR SUZIE";
...
var encodedForBob = rsaCrypt.encrypt(ENC_TEST_DATA_BOB, bobsPublicKey);`

What's the longest length for rsaCrypt.encrypt?

RegistryFactoryException when calling HashCrypt(algo: HashAlgo.Sha3_256).hash(inp: username)

I tried to implement a static key using username, see the example below. but, I get RegistryFactoryException

  static String getKey(String username) {
    var dbKey = HashCrypt(algo: HashAlgo.Sha3_256).hash(inp: username);

    return dbKey;
  }

I'm referring to this code example:
#35, another thing i noticed was they use getFromMap, which I have not idea what it should do

Environment: Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, v1.17.5, on Mac OS X 10.15.6 19G73, locale en-US)

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 11.6)
[✓] Android Studio (version 3.6)
[✓] VS Code (version 1.47.3)
[✓] Connected device (1 available)

• No issues found!

What am I trying to do?
I'm trying to implement a small method that uses userID/PWD to store and retrieve data from an SQFLITE storage. The idea I have is to use have is to aes.ctr to encrypt. Then, send the data to the storage, finally when querying, I will use aes.ctr.decrypt.

I noticed that my mEncrypt is working, but mDecrypt does not, I'm pretty sure it is due to the genFortuna uses a new key, which is different from the original used for Encrypt

voud mEncrypt {
    var keyGen = CryptKey();
    var key32 = keyGen.genFortuna(len: 32);
    var aes = AesCrypt(key: key32, padding: PaddingAES.pkcs7);
    var iv16 = keyGen.genDart(len: 16);
    var crypted2 = aes.ctr.encrypt(inp: text, iv: iv16); //Encrypt.
}

voud mDecrypt {
     var keyGen = CryptKey();
    //generate 32 byte key using Fortuna
    var key32 = keyGen.genFortuna(len: 32);

    // generated AES encrypter with key + padding
    var aes = AesCrypt(key: key32, padding: PaddingAES.pkcs7);
    //generate iv for AES
    var iv16 = keyGen.genDart(len: 16);
    var decrypt = aes.ctr.decrypt(enc: text, iv: iv16); //Decrypt.
}

Null safety

Is there a plan in the near future for null safety in this package?
Null safety is now fully launched with flutter 2.

AES-256-GCM

Does steel_crypt has support for AES-256-GCM encryption/decryption?

Feature suggestion: encoding to PEM

After having read the documentation, I don't think you have a method to encode public and private key to PEM and storing it as a string. Is it possible to add this? I'd like to use this feature so I can store it in FlutterSecureStorage since it only accepts strings.

Investigate AES-GCM divergence, tag

Following up on issue #11

The following code:

    List<int> key128bit=[
      122,140,235,87,
      10,140,37,178,
      172,182,154,240,
      211,126,138,11
    ];
    List<int> encodeIV=[
      0,0,0,0,
      1,1,1,1,
      2,2,2,2
    ];
    String plaintext='a sample plaintext';   // utf-8 encoded in AesCrypt.encrypt()

    AesCrypt encrypter=AesCrypt(
      mode: ModeAES.gcm,
      padding: PaddingAES.pkcs7,   // Setting this to "none" results in an exception
      key: base64.encode(key128bit)
    );

    String result=encrypter.encrypt(plaintext, iv: base64.encode(encodeIV));

    dev.log("plain.length=${plaintext.length}");
    dev.log("result.length=${base64.decode(result).length}");
    dev.log(base64.decode(result).toString());

Results in the output :

[log] plain.length=18
[log] result.length=32
[log] [57, 126, 210, 236, 146, 205, 233, 139, 16, 45, 193, 146, 164, 250, 98, 165, 147, 120, 153, 51, 116, 146, 11, 111, 218, 175, 8, 183, 211, 164, 245, 44]

Encrypting the same string (in utf-8) with the same key and the same IV in Firefox using subtle.crypto (but setting tag-length to 96 bits) results in the following byte sequence:

[ 57 126 210 236 146 205 233 139 16 45 193 146 164 250 98 165 147 120  73 255 75 137 95 252 156 90 215 157 98 122 ]

The sequences match for the first 18 bytes after which they diverge - if I understand it correctly, they should be identical (to the shortest length).

Furthermore, as referenced in #11 , an input string of 88 bytes resulted in a 64-bit tag (8 bytes) but this sample code results in a 112-bit tag (14 bytes).

To sum it up - there appears to be two major and one minor problem:

  1. The AES-GCM tag appears garbled.
  2. There is no way (currently) to set the tag length.
  3. (minor) PaddingAES.none results in an exception.

If I can provide any more information or help in any other way, just ask.

'SecureRandom' is imported from both 'package:encrypt/encrypt.dart' and 'package:pointycastle/api.dart'.

i had no issue running flutter pub get but when i flutter run i had this issue

Xcode build done.                                           24.9s
Failed to build iOS app
Error output from Xcode build:
↳
    ** BUILD FAILED **


Xcode's output:
↳
    ../../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/steel_crypt-0.5.5+1/lib/src/steel_crypt_base.dart:14:1: Error: 'SecureRandom' is imported from both 'package:encrypt/encrypt.dart'
    and 'package:pointycastle/api.dart'.
    import 'package:pointycastle/api.dart';
    ^^^^^^^^^^^^

    Command PhaseScriptExecution failed with a nonzero exit code
    note: Using new build system
    note: Planning build
    note: Constructing build description

Could not build the application for the simulator.
Error launching application on iPhone 11.
flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 1.20.2, on Mac OS X 10.15.6 19G2021, locale en-MY)
 
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.1)
[✓] Xcode - develop for iOS and macOS (Xcode 11.3.1)
[✓] Android Studio (version 3.4)
[✓] VS Code (version 1.48.2)
[✓] Connected device (1 available)

• No issues found!
dependencies:
  flutter:
    sdk: flutter
  cupertino_icons: ^0.1.3
  rxdart: ^0.24.1
  barcode_scan: any
  path_provider: ^1.6.11
  flutter_email_sender: ^3.0.1
  http: ^0.12.2
  state_notifier: ^0.6.0
  provider: ^4.3.2+1
  flutter_state_notifier: ^0.6.1
  steel_crypt: ^0.5.3+2

sorry i didn't realised it is an old version steel_crypt. Closing this

Uint64List is not supported in the web

I tried to use your pacakge in web app to encrypt essential data before sending to remote side but I got the exception Uint64List is not supported in the web. Is it possible to fix this? Or is there altenative way to use symmetric encryption?

Exception happens in method _computeInitialCounter of CGMBlockCipher class in row 65.

P.S. As I noticed this package is not ready for web... use another one.

Cannot call has pass in PBKDF2 mode

I am getting the error Unhandled Exception: type 'ScryptParameters' is not a subtype of type 'Pbkdf2Parameters' of 'params' in version 2.0.0 beta.
I've found a possible cause in code. On file lib/src/encoded/pass.dart, the algorithm for PBKDF2 is set as P, on line 49, but on line 61 the code is checking if algorithm contains PBKDF2, which will never be true, because it's set with P, then the error occurs.
I think this can be a bug.

AES string only input limits key options

We are only able to input string key to AesCrypt, which will most probably come encoded as base64ulr from the key generator. That is 6 bits of information per character.

var key = utf8.encode(_key32);

At this stage this get converted to a Unit8List where the first two bits will always be 0 thus reducing the possible key space by 1/4. We then assume we are using a 256bit key where it is only equivalent to 192 bit key.

Suggestion: Enable passing a raw key or sting encoded using base64url and convert it to bytes accordingly.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.