develooper Front page | perl.beginners | Postings from December 2005

Re: encode base64 password

Thread Previous
From:
Adriano Ferreira
Date:
December 22, 2005 03:27
Subject:
Re: encode base64 password
Message ID:
73ddeb6c0512220327q53621aa3q8714fe29f8aaa6d3@mail.gmail.com
On 12/22/05, Ken Perl <kenperl@gmail.com> wrote:
> Is the MIME::Base64 support unicode?

MIME::Base64 supports conversion of binary data into a limited character set,
convenient for transmission by e-mail and other means that prefer pure ASCII
data.

> I am trying to use the module to encode the  a password.

Passwords protected by such a straightforward encoding/decoding are
not protected. If you have serious concerns about security, try
something like the Digest::* modules (available at CPAN).

> In the doc http://support.microsoft.com/default.aspx?scid=kb;en-us;263991
> there is one line like this unicodePwd::IgBuAGUAdwBQAGEAcwBzAHcAbwByAGQAIgA=
> the encoded string is what I want to produce using the module, I tried this,

The point is:
(1) first they took the string "newPassword" (including the quotes)

     $s = q{"newPassword"};

(2) converted it to bytes via utf-16le (take a look at "perldoc perlunicode")

     use Encode;
     $octets = encode("utf-16le", $s);

(3) and then applied base64 encoding

     $encoded = encode_base64($octets);

(4) which resulted in

     print $encoded;

     > IgBuAGUAdwBQAGEAcwBzAHcAbwByAGQAIgA=

So the code you want is

#!/usr/bin/perl

use MIME::Base64;
use Encode;

$s = q{welcome};
$octets = encode("utf-16le", $s);
$encoded = encode_base64($octets);
print $encoded;

__END__
below is the output,
dwBlAGwAYwBvAG0AZQA=

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About