Comments (5)
Can you provide an example of what you are trying to do? Which cipher are you trying to use?
from arduinolibs.
I want to use either AES256, AESTiny256, or AESSmall256
I want to do something like this:
String in = "This Is a very long text, which much longer than 16";
setKey(_keyOfLength32);
String out = myEncrypt(in);
.....
String encryptedString = out;
setKey(_keyOfLength32);
String decryptedString = myDecrypt(encryptedString);
Im not able to use Strings that are longer than 16. Im looking for an example to write the functions "myEncrypt()" and "myDecrypt"
from arduinolibs.
The AES block ciphers on their own are not useful for encrypting large blocks of data. They are a building block. What you need is to wrap the block cipher with a mode like CTR, GCM, EAX, or XTS. Then you can encrypt or decrypt as much data as you would like. Some brief examples here:
http://rweather.github.io/arduinolibs/classCTR.html
http://rweather.github.io/arduinolibs/classGCM.html
Some background information on block cipher modes and when to apply them:
https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation
from arduinolibs.
Thanks allot for your reply!!!
I did some tests with CTR. But it seems to cut of the last part of my strings.
I have created these functions:
String My_Secure::encrypt(String msg){
ctr.clear();
ctr.setKey(_key, 32);
ctr.setIV(_iv, 16);
ctr.setCounterSize(16);
uint8_t out[msg.length()+1];
uint8_t in[msg.length()];
msg.getBytes(in, msg.length());
ctr.encrypt(out, in, msg.length());
out[msg.length()-1] = '\0';
return String(reinterpret_cast<const char*> (out));
}
String My_Secure::decrypt(String msg){
ctr.clear();
ctr.setKey(_key, 32);
ctr.setIV(_iv, 16);
ctr.setCounterSize(16);
uint8_t out[msg.length()+1];
uint8_t in[msg.length()];
msg.getBytes(in, msg.length());
ctr.decrypt(out, in, msg.length());
out[msg.length()-1] = '\0';
return String(reinterpret_cast<const char*> (out));
}
and i tested with these code:
String out = "String with a length of 65 .....................................!";
String eout = _secure->encrypt(out);
String dout = _secure->decrypt(eout);
Serial.printf("Orig: %d | Encrypted: %d | Decrypted: %d\n",out.length(), eout.length(),dout.length() );
Result:
Orig: 65 | Encrypted: 63 | Decrypted: 62
Did i missed something on ctr.setKey(_key, 32), ctr.setIV(_iv, 16), or ctr.setCounterSize(16)?
from arduinolibs.
did you find a way to do that?
would you please post it
from arduinolibs.
Related Issues (20)
- Asymmetric encryption/decryption? HOT 3
- Error compiling for new Arduino core for the ESP32 HOT 4
- Support for XChaCha20 Poly1305 HOT 2
- Need help with ChaCha and Strings HOT 1
- TestSpeck.ino fails on samd21 M0 after changing the plaintext HOT 1
- Asymmetric encryption HOT 1
- Including libraries does not work in platformio HOT 1
- default key? HOT 4
- Bug of Ascon128.c++ in Arduino Cryptography Library HOT 3
- TestSpeck.ino - Decryption fails for SpeckTiny with all key sizes HOT 1
- Crypto doesn't support next generation AVRs HOT 18
- ’SHA256‘ was not declared in this scope ESP32S3 HOT 6
- Crypto library "Hash.h" conflicting with ESP866 Arduino package "Hash.h" HOT 5
- Ascon128::decrypt doesn't seem to allow for inplace decryption, despite documentation saying so
- Support for SHA-512/256?
- crypto_feed_watchdog was not declared in this scope [ESP8266 & ESP32] HOT 3
- RNG.cpp include of <Arduino.h> makes native builds for unit testing and debugging fail
- Error Compiling for ESP8266 or ESP32 clean() not declared in scope AES CFB example
- calculated shared secret doesn't match (Diffie-Hellman, Curve25519)
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 arduinolibs.