Yubico Forum https://forum.yubico.com/ |
|
AES keys: ascii<->hex https://forum.yubico.com/viewtopic.php?f=16&t=300 |
Page 1 of 1 |
Author: | Greg Woods [ Wed Mar 25, 2009 4:25 pm ] |
Post subject: | AES keys: ascii<->hex |
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 |
Author: | Dick [ Wed Mar 25, 2009 10:13 pm ] |
Post subject: | Re: AES keys: ascii<->hex |
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 |
Author: | Jakob [ Fri Mar 27, 2009 3:26 pm ] |
Post subject: | Re: AES keys: ascii<->hex |
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 |
Author: | firnsy [ Mon Apr 13, 2009 10:42 am ] |
Post subject: | Re: AES keys: ascii<->hex |
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 |
Page 1 of 1 | All times are UTC + 1 hour |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |