diskgetor Posted August 6, 2015 Posted August 6, 2015 (edited) 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, 2015 by diskgetor
b30wulf Posted August 6, 2015 Posted August 6, 2015 (edited) 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, 2015 by b30wulf
simple Posted August 6, 2015 Posted August 6, 2015 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
diskgetor Posted August 7, 2015 Author Posted August 7, 2015 (edited) 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, 2015 by diskgetor
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now