Posted August 6, 201510 yr look here des soure:https://tls.mbed.org/des-source-codenow i write code for DES ECB ENCODE:des_const des:setkey :des_crype_ecb(&des,input,output);now,encode was ok,but how i write the DES ECB decode codes? Edited August 6, 201510 yr by diskgetor
August 6, 201510 yr Quick look on api doc, tells you use same function for encryption and decrypt 64bit block.Always clear des context at the end and initialize it again for decrypt.Parameters ctx 3DES context input 64-bit input block output 64-bit output blockReturns 0 if successfulint mbedtls_des3_crypt_ecb ( mbedtls_des3_context * ctx, const unsigned char input[8], unsigned char output[8]Parameters ctx 3DES context input 64-bit input block output 64-bit output blockReturns 0 if successful Edited August 6, 201510 yr by b30wulf
August 6, 201510 yr Well I think DES uses the same routines for encryption & decryption, try decrypting w/the same call & key. imho - i'd just use openssl, at least in C & C++ it's by far the most used, fully portable, crypto lib - http://www.codealias.info/technotes/des_encryption_using_openssl_a_simple_example
August 7, 201510 yr Author yeah,thank you again.the DES ECB was ok,but base64 was wrong.i write thses codes late got the VAR:base64result is : null .-------------------------------------------------------------------------------------------------------------------------#include "polarssl/base64.h"#include "library/base64.c"#include <stdio.h>#include <string.h>int main(void){ unsigned char base64mingwen[128]={"1122334455667788"}; unsigned char base64result[128]={0};size_t dlen;//size_t slen=128; //dlen=strlen(base64mingwen);base64_encode(base64mingwen,&dlen,base64result,slen); printf("%s",base64result); printf("\n"); getchar();}//the base64 source codes on here:https://tls.mbed.org/base64-source-code// Edited August 7, 201510 yr by diskgetor
Create an account or sign in to comment