Decode base64 string and write to file

I do not know how you manage to do this, but the line endings \r\n in your string seem to be there as 4-byte character sequences, not as 2-byte escaped CRLF. If I copy your file into a ruby string with single ticks: unescaped=’PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48cmV2aWV3LWNhc2UgY3JlYXRl\r\nZGF0ZT0iMTMvTWFyLzIwMTQgMDk6MDQ6NTEiIHN5c3RlbT0iVHJhZmlndXJhX1RlbXBsYXRlX01h\r\nbmFnZW1lbnRfdjUuMSIgYmF0Y2hpZD0iMCIgdHJhbnNhY3Rpb25ubz0iMSIgYmF0Y2huYW1lPSJH’ Base64.decode64(unescaped) #=> garbled text for every second line if I do … Read more

Why does k8s secrets need to be base64 encoded when configmaps does not?

Secrets can contain binary data (the type is map[string][]byte), and byte arrays are base64-encoded in JSON serialization. ConfigMaps only contain string data (the type is map[string]string), so the JSON serialization just outputs the string. In 1.10, ConfigMaps have a new binaryData field that allows storing binary data, which is base64-encoded, just like secrets. https://github.com/kubernetes/kubernetes/pull/57938

Base64 Encoding safe for filenames?

Modified Base64 (when /,= and + are replaced) is safe to create names but does not guarantee reverse transformation due to case insensitivity of many file systems and urls. Base64 is case sensitive, so it will not guarantee 1-to-1 mapping in cases of case insensitive file systems (all Windows files systems, ignoring POSIX subsystem cases). … Read more

Using raw image data from ajax request for data URI

Thanks for that. I’ve done a bit more digging on this and it turns out there is a solution at least on current versions of Firefox and Chrome (EDIT: IE10 works too). You can use XMLHttpRequest2 and use a typed array (Uint8Array). The following code works: <!DOCTYPE html> <html> <head> <script type=”text/javascript”> function init() { … Read more

How to Base64 encoding on the iPhone

You can see an example here. This is for iOS7+. I copy the code here, just in case: // Create NSData object NSData *nsdata = [@”iOS Developer Tips encoded in Base64″ dataUsingEncoding:NSUTF8StringEncoding]; // Get NSString from NSData object in Base64 NSString *base64Encoded = [nsdata base64EncodedStringWithOptions:0]; // Print the Base64 encoded string NSLog(@”Encoded: %@”, base64Encoded); // … Read more

Convert byte[] to base64 and ASCII in Python

The simplest approach would be: Array to json to base64: import json import base64 data = [0, 1, 0, 0, 83, 116, -10] dataStr = json.dumps(data) base64EncodedStr = base64.b64encode(dataStr.encode(‘utf-8’)) print(base64EncodedStr) print(‘decoded’, base64.b64decode(base64EncodedStr)) Prints out: >>> WzAsIDEsIDAsIDAsIDgzLCAxMTYsIC0xMF0= >>> (‘decoded’, ‘[0, 1, 0, 0, 83, 116, -10]’) # json.loads here ! … another option could be using … Read more

base64 doesnt have -w option in Mac

Yes, the default macOS base64 implementation doesn’t have the -w flag. What does that flag do? -w, –wrap=COLS Wrap encoded lines after COLS character (default 76). Use 0 to disable line wrapping. And here’s the macOS man page for base64: -b count –break=count Insert line breaks every count characters. Default is 0, which generates an … Read more

Determine if string is in base64 using JavaScript

Building on @anders-marzi-tornblad’s answer, using the regex to make a simple true/false test for base64 validity is as easy as follows: var base64regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/; base64regex.test(“SomeStringObviouslyNotBase64Encoded…”); // FALSE base64regex.test(“U29tZVN0cmluZ09idmlvdXNseU5vdEJhc2U2NEVuY29kZWQ=”); // TRUE Update 2021 Following the comments below it transpires this regex-based solution provides a more accurate check than simply try`ing atob because the latter doesn’t … Read more