Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re^2: Errors in Crypt::OpenSSL::RSA (from 'RSA.xs')

by golux (Chaplain)
on Apr 28, 2018 at 19:44 UTC ( #1213738=note: print w/replies, xml ) Need Help??

in reply to Re: Errors in Crypt::OpenSSL::RSA (from 'RSA.xs')
in thread Errors in Crypt::OpenSSL::RSA (from 'RSA.xs')

Good catch -- thank you! That now works in the example I provided.
Result 'A quick brown fox jumps over the lazy dog.'

The ironic thing is that I introduced the bug you found when moving to the shorter example; it's not in the original. The original code is much longer, and within a module I'm writing to handle SSH handshaking between a Client and remote Server. Both the original program and the example have the same symptoms though; the error message is the same.

So I've got some work to do... I now have a working (finally!) example, and a longer program with the error. I'll work at it from both ends, and post what I find here. Ideally I did something else stupid in the original, and it'll be easy to find and fix.

Edit:   Found it. Well, it was not as stupid as the short example perhaps. I wasn't getting the same data over the socket that I was sending. I kludged up some routines to calculate an md5sum on the data at different stages, and realized that, differing from what I believed about MIME::Base64, the encode_base64() method was inserting newline into the string. (I know my example didn't show the encode_base64() and decode_base64 methods(), but that was because I was getting the error without them).

So I went back to the docs for MIME::Base64 and found:

encode_base64( $bytes ) encode_base64( $bytes, $eol ); Encode data by calling the encode_base64() function. The f +irst argument is the byte string to encode. The second argument + is the line-ending sequence to use. It is optional and defaults t +o "\n". The returned encoded string is broken into lines of no more + than 76 characters each and it will end with $eol unless it is empt +y. Pass an empty string as second argument if you do not want the e +ncoded string to be broken into lines.
When I changed the $eol char from "\n" to "", the Client was able to get the full string, and it fixed the problem. :D
say  substr+lc crypt(qw $i3 SI$),4,5

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1213738]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2020-11-26 02:07 GMT
Find Nodes?
    Voting Booth?

    No recent polls found