Hi Dave and Walter, Thanks for our reply.
I'm not doing anything different for the ssh pubkey. I'm able to decode it using the "openssl enc -base64 -d -A" command. But not using the C program. Attaching my entire code here. After getting the base64 decoded I'm calculating the MD5 sum and printing it. This works for a regular string but not for SSH pubkey. Thanks again. --Prashant On 18 March 2015 at 18:04, Walter H. <walte...@mathemainzel.info> wrote: > Hi, > > before calling this function, > remove any whitespace; > > Walter > > > > _______________________________________________ > openssl-users mailing list > To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-users > >
#include <openssl/md5.h> #include <openssl/sha.h> #include <openssl/hmac.h> #include <openssl/evp.h> #include <openssl/bio.h> #include <openssl/buffer.h> #include <string.h> #include <stdio.h> char *b64_decode(unsigned char *input, int length); char* md5_digest(char *string); int main() { char *str = "AAAAB3NzaC1yc2EAAAADAQABAAABAQC/KdcFv09+f+tJK9IZ8I+L0zG7dUINClI5v8FlHJsBPSM3DDO2DpwIg/KqZKCRH9y6lEO+QAJt2DTEq/LBZcBUCdeiX1TXPFRorX+VdZigj7av/S/UHkq2EH6hfkJB3oLA5ZOZioMOAuDv1ng/DE4pRBr+KZ2oVhGjf3wa0hWi21vTZqb3s7vh+bPf6C2eUmAQJKHvFhtBK8Xx7FxN0b7igsGbk7ObwcItfMxdzkMvuiuU/UnthFVpa8wZIObFDi3MxJuf3/R+h6R1lFMvEIrU6CWRupS7Pqkm4X3qWQfhAWbdgdbD5KAk5JLA2eWIPQQA5Uay5CeH+GXz8gCa4zaz"; printf("Base64 decoded string is : %s\n", b64_decode(str, strlen(str))); // This should print binary for a ssh key. printf("MD5 Sum of the decoded string is : %s\n", md5_digest(b64_decode(str, strlen(str)))); return 0; } char *b64_decode(unsigned char *input, int length) { BIO *b64, *bmem; char *buffer = (char *)malloc(length); memset(buffer, 0, length); b64 = BIO_new(BIO_f_base64()); bmem = BIO_new_mem_buf((void*)input, length); bmem = BIO_push(b64, bmem); BIO_set_flags(bmem, BIO_FLAGS_BASE64_NO_NL); BIO_read(bmem, buffer, length); BIO_free_all(bmem); return buffer; } char* md5_digest(char *string) { int i; unsigned char result[MD5_DIGEST_LENGTH]; // Length of MD5 signature is 32 ! char * md5_sig = (char *) malloc(33); MD5(string, strlen(string), result); // output for(i = 0; i < MD5_DIGEST_LENGTH; i++){ sprintf( &md5_sig[i*2], "%02x", result[i]); } return md5_sig; }
_______________________________________________ openssl-users mailing list To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-users