Base64 encoding of binary file content

For testing a base64Binary XML type at one of my projects I needed an example of a base64 encoded file content. There is a simple command for that (at least when you are working on a Mac). For a file called ‘abc.pdf’ the command is:

openssl base64 -in abc.pdf -out encoded.txt

The result is a file ‘encoded.txt’ with a base64 decoded string:

...
JfsPu3+h42VuZHN0cmVhbQplbmRvYmoKNyAwIG9iagoxOTMzMzIxCmVuZG9iago4
IDAgb2JqCjw8Ci9UeXBlIC9DYXRhbG9nCi9QYWdlcyAyIDAgUgo+PgplbmRvYmoK
NSAwIG9iago8PAovVHlwZSAvUGFnZQovUGFyZW50IDIgMCBSCi9Db250ZW50cyA5
IDAgUgovUmVzb3VyY2VzIDExIDAgUgovQW5ub3RzIDEyIDAgUgovTWVkaWFCb3gg
WzAgMCA4NDIgNTk1XQo+PgplbmRvYmoKMTEgMCBvYmoKPDwKL0NvbG9yU3BhY2Ug
PDwKL1BDU3AgNCAwIFIKL0NTcCAvRGV2aWNlUkdCCi9DU3BnIC9EZXZpY2VHcmF5
Cj4+Ci9FeHRHU3RhdGUgPDwKL0dTYSAzIDAgUgo+PgovUGF0dGVybiA8PAo+Pgov
Rm9udCA8PAo+PgovWE9iamVjdCA8PAovSW02IDYgMCBSCj4+Cj4+CmVuZG9iagox
MiAwIG9iagpbIF0KZW5kb2JqCjkgMCBvYmoKPDwKL0xlbmd0aCAxMCAwIFIKL0Zp
bHRlciAvRmxhdGVEZWNvZGUKPj4Kc3RyZWFtCnictVJNT8MwDL37V/iMRGo7TZac
i4TgMKnqgQPigMrHNNFB2IG/PyfZRjUhgQTEUpznPPe9qG4uh3t83mLTDW847nM3
ABnrYl1IGufzggTT2np0UQwL6cJxgoQJeuh1zzmBlN666/VBhEpsxw00VR5qZeiW
evrQhmtFa7y90/Sw/2ImTCC8iOZg62UO2VtnApFErdMpzOQV3JzhRm2x8UQuLKwv
sifwN0bTsZVLzFt/oFuq1gsyieD7Izzlx/+j4/RJM8GxtMcfnjG1QuzD9xqsduqY
MMdiMKdxwuZq8ogXr+UZdS7+aibSFwSZEbCHHV8QnjdlbmRzdHJlYW0KZW5kb2Jq
CjEwIDAgb2JqCjI0NAplbmRvYmoKMiAwIG9iago8PAovVHlwZSAvUGFnZXMKL0tp
ZHMgClsKNSAwIFIKXQovQ291bnQgMQovUHJvY1NldCBbL1BERiAvVGV4dCAvSW1h
Z2VCIC9JbWFnZUNdCj4+CmVuZG9iagp4cmVmCjAgMTMKMDAwMDAwMDAwMCA2NTUz
NSBmIAowMDAwMDAwMDA5IDAwMDAwIG4gCjAwMDE5MzQ1MTcgMDAwMDAgbiAKMDAw
MDAwMDE3NSAwMDAwMCBuIAowMDAwMDAwMjcwIDAwMDAwIG4gCjAwMDE5MzM4NzIg
MDAwMDAgbiAKMDAwMDAwMDMwNyAwMDAwMCBuIAowMDAxOTMzODAwIDAwMDAwIG4g
CjAwMDE5MzM4MjMgMDAwMDAgbiAKMDAwMTkzNDE3OSAwMDAwMCBuIAowMDAxOTM0
NDk3IDAwMDAwIG4gCjAwMDE5MzM5OTIgMDAwMDAgbiAKMDAwMTkzNDE1OSAwMDAw
MCBuIAp0cmFpbGVyCjw8Ci9TaXplIDEzCi9JbmZvIDEgMCBSCi9Sb290IDggMCBS
Cj4+CnN0YXJ0eHJlZgoxOTM0NjE1CiUlRU9GCg==

As you can see I make use of the openssl library that comes with Mac OS X Maverick. You can use this content in your (XML) messages as a Base64 string for testing purposes.

About Pascal Alma

Pascal is a senior IT consultant and has been working in IT since 1997. He is monitoring the latest development in new technologies (Mobile, Cloud, Big Data) closely and particularly interested in Java open source tool stacks, cloud related technologies like AWS and mobile development like building iOS apps with Swift. Specialties: Java/JEE/Spring Amazon AWS API/REST Big Data Continuous Delivery Swift/iOS
This entry was posted in XML/ XSD/ XSLT and tagged , . Bookmark the permalink.