Comments (3)
When not padded, inputs should be multiples of the block size. Can you share your input or an input that reproduces the error?
from encrypt.
Hi @leocavalcante 👋
Sure thing. I'm trying to encrypt a String of 'String'
.
var encrypted = crypto.encrypt('String');
print(encrypted.base16);
I get this error: flutter: Another exception was thrown: RangeError (index): Index out of range: index should be less than 6: 6
On a higher level, what I'm trying to do is be able to encrypt/decrypt in my Flutter app (using encrypt
) and my web app (using aesjs
). Aesjs (using Aes.ctr), does not require padding as per their example below:
var key = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ];
// Convert text to bytes
var text = 'Text may be any length you wish, no padding is required.';
var textBytes = aesjs.utils.utf8.toBytes(text);
// The counter is optional, and if omitted will begin at 1
var aesCtr = new aesjs.ModeOfOperation.ctr(key, new aesjs.Counter(5));
var encryptedBytes = aesCtr.encrypt(textBytes);
// To print or store the binary data, you may convert it to hex
var encryptedHex = aesjs.utils.hex.fromBytes(encryptedBytes);
console.log(encryptedHex);
// "a338eda3874ed884b6199150d36f49988c90f5c47fe7792b0cf8c7f77eeffd87
// ea145b73e82aefcf2076f881c88879e4e25b1d7b24ba2788"
// When ready to decrypt the hex string, convert it back to bytes
var encryptedBytes = aesjs.utils.hex.toBytes(encryptedHex);
// The counter mode of operation maintains internal state, so to
// decrypt a new instance must be instantiated.
var aesCtr = new aesjs.ModeOfOperation.ctr(key, new aesjs.Counter(5));
var decryptedBytes = aesCtr.decrypt(encryptedBytes);
// Convert our bytes back into text
var decryptedText = aesjs.utils.utf8.fromBytes(decryptedBytes);
console.log(decryptedText);
// "Text may be any length you wish, no padding is required."
If I encrypt the string 'String'
in aesjs
and print the base16 result, I get this:
0d957ea17dad
If I encrypt the string 'String'
in encrypt
without setting padding: null
, I get this:
0d957ea17dad88c50c817dac320c1bbc
But if I set padding: null
, I get this error: flutter: Another exception was thrown: RangeError (index): Index out of range: index should be less than 6: 6
Would you mind elaborating on your point, with respect to what I'm trying to do as per above? I'm quite new to encryption. Thanks for your time.
from encrypt.
I managed to figure this out. Ended up using CBC instead of CTR, with padding. Closing this issue.
from encrypt.
Related Issues (20)
- I can't decrypt the text in 5.0.3 😕 HOT 11
- Output double in size, AES in CTR
- After RSA public key encryption, I am unable to decrypt it. It shows an error message: 'Error: Expected a value of type 'ASN1Integer', but got one of type 'ASN1Sequence'.
- Getting Private Key Issue HOT 1
- Invalid argument(s): Initialization vector must be the same length as block size
- You can add an onProgress
- Invalid argument(s): Invalid or corrupted pad block HOT 6
- Different encrypted output
- Encryption between platforms
- Web release Invalid or corrupted pad block HOT 3
- '(x >= 0) && (x <= _MASK_32)': is not true
- Exception has occurred. ArgumentError (Invalid argument(s): Invalid or corrupted pad block) HOT 11
- About Privacy Manifest HOT 1
- RSAKeyParser is not defined in poiintycastle
- [v5.0.3][Web] decrypt incorrect HOT 6
- crypto dependency issue
- Insecure Random on ios
- Invalid argument(s): Invalid or corrupted pad block HOT 10
- (mistake) `Key.stretch` should be a factory constructor HOT 1
- OpenSSL's EVP envelope HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from encrypt.