Code Monkey home page Code Monkey logo

arduino-base64's Introduction

Introduction

This library provides methods for encoding binary into base64 strings and the reverse operation.

arduino-base64's People

Contributors

adamvr avatar fuho avatar kaidokert avatar karl-petter avatar nfriedly avatar sivieri 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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

arduino-base64's Issues

base64_enc_len should return a bigger size

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.

  • input* is placed to address 3FFEFBE0
  • encoded* is placed to address 3FFEFBD0
  • so nul-terminator of "encoded" overwrites the first byte of input
  • so input seems to be consumed.

Fix is easy:

int base64_enc_len(int plainLen) {
return ((plainLen + 2 - ((plainLen + 2) % 3)) / 3 * 4)+1;
}

Compile error

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

Tutorial request

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)

wrong encoding

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==

Thank you! arduino-base64 is great!

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

Need to reduce input length by 1 to be compatible with HTTP basic authentication

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=

some problem with the library not sure what

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.

Source is being modified.

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.

convert image into string

I want to covert image that is store into arduino sdcard to string using base64 can it possible or not?

Base64 encoding differs from the Erlang one

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?

Set source code license

Could you set the license of your source code in order to know if I can use it, modify it ..?

Regards,
Mimil,

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.