Encoding a string to base64

Hi,

I recently downloaded a source code (n_cryptoapi) which i
have tried using to encode a string to base64 but i'm
getting incorrect results.

string = 0116112006003
actual result = MAAxADEANgAxADEAMgAwADAANgAwADAAMwA=
expected result = MDExNjExMjAwNjAwMw

what am i doing wrong?
I'm using the encode64 function =

String ls_encoded
ULong lul_len, lul_buflen
Boolean lb_rtn

lul_len = Len(ablob_data)

lul_buflen = lul_len * 2

ls_encoded = Space(lul_buflen)

lb_rtn = CryptBinaryToString(ablob_data, &
				lul_len, CRYPT_STRING_BASE64, &
				ls_encoded, lul_buflen)

If lb_rtn Then
	ls_encoded = of_ReplaceAll(ls_encoded, "~r~n", "")
Else
	ls_encoded = ""
End If

Return ls_encoded

The function is expecting a blob as an argument. So i just
blob the string -

ablob_data = blob('0116112006003') and then pass that
variable to the function. Anybody have any idea what is
wrong?
Thanks.
0
Jason
5/25/2010 9:53:53 AM
sybase.powerbuilder.general 62418 articles. 19 followers. Follow

2 Replies
2689 Views

Similar Articles

[PageSpeed] 48

I assume you have PB10 or bigger. These versions are unicode.
Try ablob_data = blob('0116112006003', EncodingAnsi!) 

Regards
Arthur
-- 



Jason L wrote:

> Hi,
> 
> I recently downloaded a source code (n_cryptoapi) which i
> have tried using to encode a string to base64 but i'm
> getting incorrect results.
> 
> string = 0116112006003
> actual result = MAAxADEANgAxADEAMgAwADAANgAwADAAMwA=
> expected result = MDExNjExMjAwNjAwMw
> 
> what am i doing wrong?
> I'm using the encode64 function =
> 
> String ls_encoded
> ULong lul_len, lul_buflen
> Boolean lb_rtn
> 
> lul_len = Len(ablob_data)
> 
> lul_buflen = lul_len * 2
> 
> ls_encoded = Space(lul_buflen)
> 
> lb_rtn = CryptBinaryToString(ablob_data, &
> 				lul_len, CRYPT_STRING_BASE64, &
> 				ls_encoded, lul_buflen)
> 
> If lb_rtn Then
> 	ls_encoded = of_ReplaceAll(ls_encoded, "~r~n", "")
> Else
> 	ls_encoded = ""
> End If
> 
> Return ls_encoded
> 
> The function is expecting a blob as an argument. So i just
> blob the string -
> 
> ablob_data = blob('0116112006003') and then pass that
> variable to the function. Anybody have any idea what is
> wrong?
> Thanks.
0
Arthur
5/25/2010 10:55:21 AM
Hi Arthur,
I was suspecting that but i tried encodingutf8! which did
not work. But didn't try encodingansi! ... that worked!
thanks arthur.

> I assume you have PB10 or bigger. These versions are
> unicode. Try ablob_data = blob('0116112006003',
> EncodingAnsi!)
>
> Regards
> Arthur
> --
>
>
>
> Jason L wrote:
>
> > Hi,
> >
> > I recently downloaded a source code (n_cryptoapi) which
> > i have tried using to encode a string to base64 but i'm
> > getting incorrect results.
> >
> > string = 0116112006003
> > actual result = MAAxADEANgAxADEAMgAwADAANgAwADAAMwA=
> > expected result = MDExNjExMjAwNjAwMw
> >
> > what am i doing wrong?
> > I'm using the encode64 function =
> >
> > String ls_encoded
> > ULong lul_len, lul_buflen
> > Boolean lb_rtn
> >
> > lul_len = Len(ablob_data)
> >
> > lul_buflen = lul_len * 2
> >
> > ls_encoded = Space(lul_buflen)
> >
> > lb_rtn = CryptBinaryToString(ablob_data, &
> >                 lul_len, CRYPT_STRING_BASE64, &
> >                 ls_encoded, lul_buflen)
> >
> > If lb_rtn Then
> >     ls_encoded = of_ReplaceAll(ls_encoded, "~r~n", "")
> > Else
> >     ls_encoded = ""
> > End If
> >
> > Return ls_encoded
> >
> > The function is expecting a blob as an argument. So i
> > just blob the string -
> >
> > ablob_data = blob('0116112006003') and then pass that
> > variable to the function. Anybody have any idea what is
> > wrong?
> > Thanks.
0
Jason
5/25/2010 11:22:16 AM
Reply:

Similar Artilces:

To Encode String or to Not Encode String... Answer?
I am importing a CSV file from a Unix server as a string, and then saving the string into a new file for later processing.  However, this process does not always work.  As this CSV file is VERY, VERY large, I am unable to immediately tell if the fault lies with my code, or the CSV file provider (very possible).  The only time I can tell that this happened is when the data is not populated the next morning.  The fault appears to lie in there being extra or missing commas, as when I try to run the data import manually, STRINGs are attempted to be inserted into INT...

check if string is base64 encoded
hey allcurrently i use the following piece of code to check if the string passed to me can be converted to base64, it is not very efficient and bad, can someone please suggest another of doing thisprivate string ConvertBase64ToString(string[] content){StringBuilder sb = new StringBuilder();int i = content.GetUpperBound(0);for (int j=0; j<i; j++){try{// if successful in converting base64 append it.sb.Append(ASCIIEncoding.ASCII.GetString(Convert.FromBase64String(content.GetValue(j).ToString())));}catch (Exception){// cannot be decoded so append the original stringsb.Append(content.GetVa...

Base64 encode zipped string
Hello Group, I want to create a set of functions that allows me to do the following: function CompressAndEncodeString(InString: string): string; begin CompressInString using zip algo or whatever Base64 encode compressed Instring and assign to result end; and function RetrieveString(Instring: string): string begin Base64 decode Instring Uncompress decodestring and assign to result end; Googled for the different parts, but got lost in the complexity. Any help is very much appreciated! Willem -- Willem van Deursen, The Netherlands wvandeursen_nospam@...

Base64 encode Latin 1 string
The app below base64 encodes a Latin 1 string. It seems unaesthetic to first convert to TBytes and then to TIdBytes to be able to call TIdEncoderMIME.EncodeBytes. Is there a simpler way to do this? This is for Delphi XE6 Update 1. {$apptype console} program TestEncode; uses System.SysUtils, IdCoder, IdCoderMIME, IdGlobal; const ISO_8859_1_Code_Page = 28591; type ISO_8859_1_String = type AnsiString( ISO_8859_1_Code_Page ); function Encoded( const S: string ): string; // MIME encode the ISO 8859-1 (Latin 1) string. var B1: TBytes; B2: TIdBytes; J: ...

Encoding image to base64 string using javascript?
I need to encode an image to a base64 string on client side, does anyone has a script to do it? ThanksIf this post has been useful to you please mark it as answer. Take a look at this url, I think it contains the info you are looking for:  http://www.codeproject.com/useritems/Exsead1.asp  I tried that but couldn't manage to get it to work.If this post has been useful to you please mark it as answer....

charset/base64 encoding/encode.
Still futzing around with email and character sets. Under Encode and perluniintro there's mention of octet \x{..} (255 chars up to \xff string some internal representation code point \x{...} 1, 2 or more bytes of data But I'm not sure about the order of things. So I'll try this: I have a MIME messsage part like the following: Content-Type: text/plain; charset="BIG5" Content-Transfer-Encoding: base64 1eLKx9K7t+JIVE1MuPHKvdDFvP6joQ0KCqFYoVihWKFYoVihWKFYoVihWKFYoVihWKFYoVihWKFY oVihWKFYoVihWKFYoVihWKFYoVihWKFYoVihWAqhaapgt06haqRX...

Encode string to html string
I need to convert a text string ("Dewey & Cheatham & Howe") to an XML encoded string ("Dewey & Cheatham & Howe"). I am not building an XML document, I am just trying to convert a single string. I have looked at the System.Xml namespace, but I can't quite find what I need. XmlTextWriter.WriteString() does the type of encoding I need, but it writes the string. I just want it to return the encoded string. Can someone tell me the class and method I need? Thanks. Pro LINQ: Language Integrated Query in C# 2008http://www.linqdev.comhttp://www.ne...

getting base64 encoded string using IdHttp
yes hello good to be back... so i have written a REST server in PHP to talk to my IdHttp client that base64 encodes a jpeg in order to send the data in a record "packet" of my own design. I then use a TStringList.delimitedText to read the received packet and parse the results into key/value pairs (kind of a homestyle JSON format). this is working well for all the other data, but it seems that the base64 field is being limited to 4096 bytes when i call the RawByteString thumb64 := tsServerReply.Values['base64field']; the original 'base64field' i...

Storing and Reading Base64 Encoded Connection String in Web.Config
Many people store database connection string in web.config file. However, web.config file being an XML file, the data stored there is in clear text format. This is especially important for connection strings because anybody can easily see your database details including user id and password. In this article we will see how you can encrypt values stored in web.config using Base64 encoding and later on decrypt them in your code. Note that Base64 encoding is not a secure algorithm but it is a quick and easy way to hide the connection string details from casual readers. http://www.dotnetbips....

How to convert a TMemoryStream into an Base64 encoded string in DelphiXE3 and vice verse?
How to convert a TMemoryStream into an Base64 encoded string in DelphiXE3 and vice verse? I know JCLMime.pas, but it works only from Stream to Stream or from ANSISTRING to ANSISTRING. Mathias Pannier wrote: > How to convert a TMemoryStream into an Base64 encoded string in > DelphiXE3 and vice verse? > > I know JCLMime.pas, but it works only from Stream to Stream or from > ANSISTRING to ANSISTRING. The built in functions do the same. Stream to stream or string to string. I would do it in two steps. 1) Encode the stream and 2) read from the destination s...

Passing Base64 encoded connection string to CreateDatabase as a parameter gives me error
Hello,I have an app.config defined as below: <?xml version="1.0" encoding="utf-8" ?><configuration>  <configSections>    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data" />   </configSections>         <dataConfiguration defaultDatabase="DMIDConnectionString"/>  <connectionStrings>    <add name="DMIDCon...

Dynamic Image(s) in page using Base64 encoded string as image source
First of all, I'm not sure where to put this in the forum.  Second, Here's my problem. I have access to a webservice that, based upon search params, will return a string array of base64 encoded images.  Now, the client application has to display those images.  Since the images come from a protected image server, I cannot use static paths or anything.  All I have to work with are the base64 encoded image strings that are returned from the service.  That's it! I am having trouble figuring out how to display these in the page once when I get them.&nbs...

Should Encode::encode affect the original string?
My platform: $ perl -V:version -MEncode -e 'print "$Encode::VERSION\n"' version='5.8.7'; 2.23 What I expected: $ perl -MEncode -e '$s='hi';Encode::encode("UTF-8", $s, 0);print "($s)\n"' (hi) Unexpected results when CHECK is 1: $ perl -MEncode -e '$s='hi';Encode::encode("UTF-8", $s, 1);print "($s)\n"' () Thanks, Stephen On Fri, Jul 06, 2007 at 09:06:20AM -0400, Stephen J. Smith wrote: > Unexpected results when CHECK is 1: > > $ perl -MEncode -e '$s='hi&...

Convert Object/String to a Base64 String
The function below converts a normal string to a Base64 string. This can come in pretty handy ;) public static string getBase64Encoded(string inString) { byte[] inData; char[] charArr; //System.IO.StringReader sr = new System.IO.StringReader(inString); //sr.Read(inData, 0, inString.Length); charArr = inString.ToCharArray(); inData = new byte[charArr.Length]; for(int i = 0; i < charArr.Length; i++) { inData[i] = (byte)charArr[i]; } return System.Convert.ToBase64String(inData, 0 , inData.Length); } ...

Web resources about - Encoding a string to base64 - sybase.powerbuilder.general

Encoding (memory) - Wikipedia, the free encyclopedia
Visual, acoustic, and semantic encodings are the most intensively used. Other encodings are also used. Acoustic encoding is the encoding of auditory ...

Twitter image encoding challenge
If a picture's worth 1000 words, how much of a picture can you fit in 140 characters? Note : That's it folks! Bounty deadline is here, and after ...

【medical-news】Genetic Variation in NR1H4 Encoding the Bile Acid Receptor FXR - 医药生命科学动态跟踪 -丁香园论坛
Context: Bile acid signaling via farnesoid X receptor (FXR) regulates glucose and lipid levels, fat mass, and hepatic steatosis in animal models.Objective: ...

HandBrake Open Source video transcoder v0.10 released with hundreds of new features including H.265 and ...
... can be used for transcribing many different types of files/codecs to almost any other. Today’s headliner updates include H.265 and VP8 encoding. ...

CJK Type - CJK Fonts, Character Sets & Encodings. All CJK. All of the time.
As I wrote nearly a year ago , the Adobe-Identity-0 ROS is useful for building special-purpose fonts, especially CJK ones whose glyph coverage ...

Link Encoding Goes Mobile With Deep Links From Bitly
... Facebook and Google have been competing to bring the best solution for tracking deeplinks . This week, Bitly announced its own linking encoding ...

Encoding Articles - AppAdvice iPhone/iPad News
Latest Encoding Articles - AppAdvice iPhone/iPad News

AirMovie - Enjoy the videos in your PC anytime, anywhere with NO ENCODING!!
Holen Sie sich „AirMovie - Enjoy the videos in your PC anytime, anywhere with NO ENCODING!!“ im App Store. Sehen Sie sich Screenshots, Bewertungen ...

More tips on encoding video for Apple TV and iPod, from us to you
Apple tells video podcasters how to encode their content, which is also useful …

Handbrake 0.9.6 gives some, takes some encoding features
The Handbrake Project has announced an update to its open-source, cross-platform video transcoding utility. Handbrake 0.9.6 includes new and ...

Resources last updated: 1/18/2016 6:37:11 PM