This library provides methods for encoding binary into base64 strings and the reverse operation.
adamvr / arduino-base64 Goto Github PK
View Code? Open in Web Editor NEWA base64 library for the arduino platform, written in C
License: MIT License
A base64 library for the arduino platform, written in C
License: MIT License
C:\Users\user\Documents\Arduino\libraries\arduino-base64-master: Missing 'paragraph' from library
There is a commentary in sample:
// note input is consumed in this step: it will be empty afterwards
base64_encode(encoded, input, inputLen);
There is no consumption of "input" in base64_encode, is it?
But the input gets consumed.
So problem lies somewhere else.
base64_enc_len( "Hello world" ) returns 16.
And base64 encode result is "SGVsbG8gd29ybGQ=", which is 16 characters, OK?
But this doesn't include terminating \0.
So memory gets overwritten.
Fix is easy:
int base64_enc_len(int plainLen) {
return ((plainLen + 2 - ((plainLen + 2) % 3)) / 3 * 4)+1;
}
I installed the library in Arduino IDE 1.6.4 but compiler gives error:
avr/pgmspace.h: No such file or directory
#include <avr/pgmspace.h>
^
compilation terminated.
Error compiling.
Thanks for suggestions, Timo
Can you provide a novice tutorial? Thank you very much. For instance, how can I import the lib to my Arduino project? I've tried to import the zip file and the folder file. They all failed.
ARDUINO UNO
ARDUINO IDE 1.0.5
ERROR:
java.lang.NullPointerException
at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:36)
at sun.reflect.UnsafeObjectFieldAccessorImpl.get(UnsafeObjectFieldAccessorImpl.java:18)
at java.lang.reflect.Field.get(Field.java:358)
at apple.awt.CAccessibility.getAccessibleRoleFor(CAccessibility.java:200)
at apple.awt.CAccessibility$11.call(CAccessibility.java:215)
at apple.awt.CAccessibility$11.call(CAccessibility.java:212)
at apple.awt.CToolkit$CallableWrapper.run(CToolkit.java:1125)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:199)
at apple.awt.CToolkit$CPeerEvent.dispatch(CToolkit.java:1215)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:715)
at java.awt.EventQueue.access$400(EventQueue.java:82)
at java.awt.EventQueue$2.run(EventQueue.java:676)
at java.awt.EventQueue$2.run(EventQueue.java:674)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:86)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:685)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:205)
at java.awt.Dialog$1.run(Dialog.java:1049)
at java.awt.Dialog$3.run(Dialog.java:1101)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.Dialog.show(Dialog.java:1099)
at javax.swing.JFileChooser.privateShowDialog(JFileChooser.java:758)
at javax.swing.JFileChooser.showDialog(JFileChooser.java:721)
at javax.swing.JFileChooser.showOpenDialog(JFileChooser.java:626)
at processing.app.Base.handleAddLibrary(Base.java:2390)
at processing.app.Base$4.actionPerformed(Base.java:955)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2028)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2351)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.AbstractButton.doClick(AbstractButton.java:389)
at com.apple.laf.ScreenMenuItem.actionPerformed(ScreenMenuItem.java:95)
at java.awt.MenuItem.processActionEvent(MenuItem.java:650)
at java.awt.MenuItem.processEvent(MenuItem.java:609)
at java.awt.MenuComponent.dispatchEventImpl(MenuComponent.java:343)
at java.awt.MenuComponent.dispatchEvent(MenuComponent.java:331)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:720)
at java.awt.EventQueue.access$400(EventQueue.java:82)
at java.awt.EventQueue$2.run(EventQueue.java:676)
at java.awt.EventQueue$2.run(EventQueue.java:674)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:86)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:690)
at java.awt.EventQueue$3.run(EventQueue.java:688)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:86)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:687)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
java.lang.NullPointerException
at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:36)
at sun.reflect.UnsafeObjectFieldAccessorImpl.get(UnsafeObjectFieldAccessorImpl.java:18)
at java.lang.reflect.Field.get(Field.java:358)
at apple.awt.CAccessibility.getAccessibleRoleFor(CAccessibility.java:200)
at apple.awt.CAccessibility$11.call(CAccessibility.java:215)
at apple.awt.CAccessibility$11.call(CAccessibility.java:212)
at apple.awt.CToolkit$CallableWrapper.run(CToolkit.java:1125)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:199)
at apple.awt.CToolkit$CPeerEvent.dispatch(CToolkit.java:1215)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:715)
at java.awt.EventQueue.access$400(EventQueue.java:82)
at java.awt.EventQueue$2.run(EventQueue.java:676)
at java.awt.EventQueue$2.run(EventQueue.java:674)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:86)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:685)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:205)
at java.awt.Dialog$1.run(Dialog.java:1049)
at java.awt.Dialog$3.run(Dialog.java:1101)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.Dialog.show(Dialog.java:1099)
at javax.swing.JFileChooser.privateShowDialog(JFileChooser.java:758)
at javax.swing.JFileChooser.showDialog(JFileChooser.java:721)
at javax.swing.JFileChooser.showOpenDialog(JFileChooser.java:626)
at processing.app.Base.handleAddLibrary(Base.java:2390)
at processing.app.Base$4.actionPerformed(Base.java:955)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2028)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2351)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.AbstractButton.doClick(AbstractButton.java:389)
at com.apple.laf.ScreenMenuItem.actionPerformed(ScreenMenuItem.java:95)
at java.awt.MenuItem.processActionEvent(MenuItem.java:650)
at java.awt.MenuItem.processEvent(MenuItem.java:609)
at java.awt.MenuComponent.dispatchEventImpl(MenuComponent.java:343)
at java.awt.MenuComponent.dispatchEvent(MenuComponent.java:331)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:720)
at java.awt.EventQueue.access$400(EventQueue.java:82)
at java.awt.EventQueue$2.run(EventQueue.java:676)
at java.awt.EventQueue$2.run(EventQueue.java:674)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:86)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:690)
at java.awt.EventQueue$3.run(EventQueue.java:688)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:86)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:687)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
java.lang.NullPointerException
at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:36)
at sun.reflect.UnsafeObjectFieldAccessorImpl.get(UnsafeObjectFieldAccessorImpl.java:18)
at java.lang.reflect.Field.get(Field.java:358)
at apple.awt.CAccessibility.getAccessibleRoleFor(CAccessibility.java:200)
at apple.awt.CAccessibility$11.call(CAccessibility.java:215)
at apple.awt.CAccessibility$11.call(CAccessibility.java:212)
at apple.awt.CToolkit$CallableWrapper.run(CToolkit.java:1125)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:199)
at apple.awt.CToolkit$CPeerEvent.dispatch(CToolkit.java:1215)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:715)
at java.awt.EventQueue.access$400(EventQueue.java:82)
at java.awt.EventQueue$2.run(EventQueue.java:676)
at java.awt.EventQueue$2.run(EventQueue.java:674)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:86)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:685)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:205)
at java.awt.Dialog$1.run(Dialog.java:1049)
at java.awt.Dialog$3.run(Dialog.java:1101)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.Dialog.show(Dialog.java:1099)
at javax.swing.JFileChooser.privateShowDialog(JFileChooser.java:758)
at javax.swing.JFileChooser.showDialog(JFileChooser.java:721)
at javax.swing.JFileChooser.showOpenDialog(JFileChooser.java:626)
at processing.app.Base.handleAddLibrary(Base.java:2390)
at processing.app.Base$4.actionPerformed(Base.java:955)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2028)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2351)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.AbstractButton.doClick(AbstractButton.java:389)
at com.apple.laf.ScreenMenuItem.actionPerformed(ScreenMenuItem.java:95)
at java.awt.MenuItem.processActionEvent(MenuItem.java:650)
at java.awt.MenuItem.processEvent(MenuItem.java:609)
at java.awt.MenuComponent.dispatchEventImpl(MenuComponent.java:343)
at java.awt.MenuComponent.dispatchEvent(MenuComponent.java:331)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:720)
at java.awt.EventQueue.access$400(EventQueue.java:82)
at java.awt.EventQueue$2.run(EventQueue.java:676)
at java.awt.EventQueue$2.run(EventQueue.java:674)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:86)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:690)
at java.awt.EventQueue$3.run(EventQueue.java:688)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:86)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:687)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Hi! Your library is really cool! Can you please send a request to add it to the Arduino Library Manager?
The library returns:
smtp.gmail.com = c210cC5nbWFpbC5jb20A
The https://www.base64encode.org/ returns:
smtp.gmail.com = c210cC5nbWFpbC5jb20=
I found a bug on library?
This is the output on an arduino due with the sample sketch:
wiki:pedia = d2lraTpwZWRpYQA=
This is however wrong. It should be "d2lraTpwZWRpYQ==".
Both string side by side:
d2lraTpwZWRpYQA=
d2lraTpwZWRpYQ==
Arduino IDE 1.6.12
'base64_enc_len' was not declared in this scope
Adam,
I found arduino-base64 and am using it in an open source project. I just wanted to say thanks - it works great!
cheers
adam
Adam Feuer
Seattle WA
In the example code... using it to authenticate a RESTAPI, I ran into a problem, but fixed it by decreasing the input size by 1.
// encoding
char input[] = "username:password";
int inputLen = sizeof(input)-1; <== Need to do this (most likely the code is processing the \0)
int encodedLen = base64_enc_len(inputLen);
char encoded[encodedLen];
// note input is consumed in this step: it will be empty afterwards
base64_encode(encoded, input, inputLen);
Serial.println(encoded);
will produce the following:
dXNlcm5hbWU6cGFzc3dvcmQ=
Here is what Apache will provide in the header for basic authentication... They match, but without decreasing the inputLen by 1, they will not.
Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=
the below one is a base64 conversion by library:
eyJldmVudCI6IlVzZXIgUmF0aW5nIiwicHJvcGVydGllcyI6eyJkaXN0aW5jdF9pZCI6IjEzNzkzIiwidG9rZW4iOiJjZDVjOTVlMzZjZTFkZmJjMzE2Mjk1MDFmODQzYTYyNSIsIkRldmljZSI6IjMyMSIsIk1vdmllSUQiOiIzMjEiLCJSYXRpbmciOiIzMjEifX0A
and this one is online based conversion:
eyJldmVudCI6IlVzZXIgUmF0aW5nIiwicHJvcGVydGllcyI6eyJkaXN0aW5jdF9pZCI6IjEzNzkzIiwidG9rZW4iOiJjZDVjOTVlMzZjZTFkZmJjMzE2Mjk1MDFmODQzYTYyNSIsIkRldmljZSI6IjMyMSIsIk1vdmllSUQiOiIzMjEiLCJSYXRpbmciOiIzMjEifX0=
both have one minute difference and that is at the end. I am using this string to upload data to an online service called Mixpanel although both fails but I want to make sure this library is making proper convesion.
Hi there,
Sorry that I am new in arduino.
I just make a test as follow:
uint8_t key[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
char data[] = "0123456789012345";
aes256_enc_single(key, data);
Serial.println(data);
Serial.println(data);
char output[base64_enc_len(sizeof(data))];
//base64_encode(output, data, sizeof(data));
aes256_dec_single(key, data);
Serial.print("decrypted:");
Serial.println(data);
This will be output correctly (the decryption is successful)
�⸮⸮⸮⸮�s⸮�B⸮⸮3⸮O
�⸮⸮⸮⸮�s⸮�B⸮⸮3⸮O
decrypted:0123456789012345
But when include back the function base64_encode(output, data, strlen(data)); it makes the decryption failed.
Kf⸮⸮eh@⸮⸮⸮I⸮⸮f⸮�
Kf⸮⸮eh@⸮⸮⸮I⸮⸮f⸮�
decrypted:⸮�⸮`:Q⸮⸮c⸮D ,⸮|⸮
Seems the encoder make some modification to the input data.
Am I missing something here..?
Thanks.
I want to covert image that is store into arduino sdcard to string using base64 can it possible or not?
Hi,
I am working on an implementation of OAuth for making authorized requests to Twitter, and I am using your library.
I have just found out that sometimes (looks like two out of three times) I obtain different values than the base64 Erlang implementation, and in these cases Twitter refuses to answer because of bad authentication.
For example, the sha-hmac implementation returns me a list of the following bytes (each value from 0 to 255, of course):
90 114 197 46 26 146 78 211 61 102 19 97 252 102 251 251 132 8 164 238
which I cast to characters and pass them to the base64_encode function, obtaining the following:
WnLFLhqSTtM9ZhNh+Gb704QIpO4=
which is refused by Twitter, while the Erlang answer (accepted by the server) with the same list is:
WnLFLhqSTtM9ZhNh/Gb7+4QIpO4=
Do you happen to have an idea of the reason behind this?
Could you set the license of your source code in order to know if I can use it, modify it ..?
Regards,
Mimil,
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.