Skip to content

Instantly share code, notes, and snippets.

@vixtory09678
Last active March 31, 2021 09:08
Show Gist options
  • Save vixtory09678/2f0fc60f00e219691f08c5b5ebcc8460 to your computer and use it in GitHub Desktop.
Save vixtory09678/2f0fc60f00e219691f08c5b5ebcc8460 to your computer and use it in GitHub Desktop.
#include <Arduino.h>
#include "rom/md5_hash.h"
extern "C" {
#include "crypto/base64.h"
}
void setup() {
Serial.begin(9600);
const char* message = "Hello World";
size_t outputLen;
unsigned char *encode = base64_encode((const unsigned char*)message, strlen(message), &outputLen);
unsigned char *decode = base64_decode(encode, outputLen, &outputLen);
unsigned char md5Out[16];
struct MD5Context md5Context;
MD5Init(&md5Context);
MD5Update(&md5Context, (const unsigned char *)message, strlen(message));
MD5Final(md5Out, &md5Context);
Serial.print("plaintext : "); Serial.println(message);
Serial.print("encode : "); Serial.println((char*)encode);
Serial.print("decode : "); Serial.println((char*)decode);
for (int i = 0; i < sizeof(md5Out); i++) {
Serial.print(md5Out[i], HEX);
} Serial.println();
}
void loop() {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment