Yubico Forum

...visit our web-store at store.yubico.com
It is currently Tue Jan 30, 2018 1:25 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: AES keys: ascii<->hex
PostPosted: Wed Mar 25, 2009 4:25 pm 
Offline

Joined: Fri Jan 09, 2009 7:23 pm
Posts: 13
Anybody got some code (or an algorithm that I can code) that will convert an AES key from encoded ASCII to hex? I need this as part of our project to integrate Yubikeys into an existing authentication infrastructure. We are using the YubiPAM module from freeradius to authenticate with Yubikeys, but I also want to be able to program the Yubikeys. This requires being able to enter the generated AES key into the database used by YubiPAM. However, the ykpasswd command used for YubiPAM wants the key in hex, whereas the ykpersonalize tool generates the key in encoded ASCII:

key:gtheuknkdtkgjfufbvridkvetnlffukh

I need a way to convert that to hex.

Thanks,
--Greg


Top
 Profile  
Reply with quote  

Share On:

Share on Facebook FacebookShare on Twitter TwitterShare on Tumblr TumblrShare on Google+ Google+

PostPosted: Wed Mar 25, 2009 10:13 pm 
Offline

Joined: Sun Jan 11, 2009 4:40 am
Posts: 41
Is it hex to modhex and modhex to hex that you're after? If so, I wrote a short program in AutoIT as a programming exercise that does that and would be happy to share the code. Keep in mind that I'm not a pro at this so making fun of my code is strictly prohibited. ;-)

modhex: GTHEUKNKDTKGJFUFBVRIDKVETNLFFUKH
hex: 5D63E9B92D9584E41FC729F3DBA44E96

Dick


Top
 Profile  
Reply with quote  
PostPosted: Fri Mar 27, 2009 3:26 pm 
Offline
Site Admin
Site Admin

Joined: Wed May 28, 2008 7:04 pm
Posts: 263
Location: Yubico base camp in Sweden - Now in Palo Alto
A C++ implementation could be done like... But there many ways to skin a cat...

static const char trans[] = "cbdefghijklnrtuv";

void encode(char *dst, const unsigned char *src, int srcSize)
{
while (srcSize--) {
*dst++ = trans[*src >> 4];
*dst++ = trans[*src++ & 0xf];
}

*dst = '\0';
}

void decode(unsigned char *dst, const char *src, int dstSize)
{
unsigned char b;
bool flag = false;
const char *p1;

for (; *src, dstSize > 0; src++) {
if ((p1 = strchr(trans, tolower(*src))) == NULL)
b = 0;
else
b = (BYTE) (p1 - trans);

if (flag = !flag)
*dst = b;
else {
*dst = (*dst << 4) | b;
dst++;
dstSize--;
}
}

while (dstSize--) *dst++ = 0;
}

Regards,

JakobE
Hardware- and firmware guy @ Yubico


Top
 Profile  
Reply with quote  
PostPosted: Mon Apr 13, 2009 10:42 am 
Offline
User avatar

Joined: Mon Jun 23, 2008 1:19 am
Posts: 12
Greg Woods wrote:
Anybody got some code (or an algorithm that I can code) that will convert an AES key from encoded ASCII to hex? I need this as part of our project to integrate Yubikeys into an existing authentication infrastructure. We are using the YubiPAM module from freeradius to authenticate with Yubikeys, but I also want to be able to program the Yubikeys. This requires being able to enter the generated AES key into the database used by YubiPAM. However, the ykpasswd command used for YubiPAM wants the key in hex, whereas the ykpersonalize tool generates the key in encoded ASCII:

key:gtheuknkdtkgjfufbvridkvetnlffukh

I need a way to convert that to hex.

Thanks,
--Greg


Greg,

It may not be documented that well but ykpasswd will accept AES keys in either hex or modhex (or encoded ascii as you refer).

firnsy

_________________
http://www.securixlive.com/yubipam


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: YahooSeeker [Bot] and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group