Base64-encoding data is found in places all over the IT world and in home users’ systems as well. Being able to encode data in Java or ECMAScript/JavaScript can be valuable when those are the languages available to you. This sample shows how to convert from one format to another and eventually encode data for use within a directory like eDirectory.

In a recent article I mentioned the possibilities of ECMAScript/Javascript within Java for scripting within Java applications or just for your own system. While working on an issue recently the need to convert a string of characters representing binary to a Base64-encoded representation of that binary value was manifest. As the issue was for use within Novell Identity Manager the following was able to be used to accept the string of binary and then convert it to a valid Base64-encoded value. The same could be done within any application with access to the com.novell.xml.util package (or a suitable replacement to do the Base64-encoding) and a Rhino implementation to run the rest of the conversion code from string to binary. ECMAScript/JavaScript Development Without a Web Browser

<code interpreter="rhino">
function b64encbinstring(binstring) {
	var mylong0 = java.lang.Long.parseLong(binstring, 2);
	var bos = new;
	var dos = new;
	var bytedata = bos.toByteArray();
	var base64c = new;
	var base64string=new, (8-Math.ceil(binstring.length/8)), Math.ceil(binstring.length/8), false));
	return base64string;

b64encbinstring('00101010110111100001010101000101101');    //Line to Base64-encode a string of zeros and ones and return the appropriate string.

This may not be the most-elegant method of doing what is needed but it was something that otherwise would have required custom Java code to do the same compiled into the application in one way or another. If somebody can condense the code above to make is simpler or avoid unnecessary steps please feel free to do so in the comments section.

2 votes, average: 5.00 out of 52 votes, average: 5.00 out of 52 votes, average: 5.00 out of 52 votes, average: 5.00 out of 52 votes, average: 5.00 out of 5 (2 votes, average: 5.00 out of 5)
You need to be a registered member to rate this post.

Disclaimer: As with everything else at NetIQ Cool Solutions, this content is definitely not supported by NetIQ, so Customer Support will not be able to help you if it has any adverse effect on your environment.  It just worked for at least one person, and perhaps it will be useful for you too.  Be sure to test in a non-production environment.

Leave a Reply

No Comments
By: ab
Nov 18, 2009
11:30 am
Active Directory Authentication Automation Cloud Computing Cloud Security Configuration Customizing Data Breach DirXML Drivers End User Management Identity Manager Importing-Exporting / ICE/ LDIF Intelligent Workload Management IT Security Knowledge Depot LDAP Monitoring Open Enterprise Server Passwords Reporting Secure Access Supported Troubleshooting Workflow