static void encode_password(const str_t password, const char verify_code[VERIFY_LEN], const uchar bits[BITS_LEN], uchar out[MD5_DIGEST_LENGTH << 1]) { str_t password_bin = str2bin(password); uchar md5_src_1[MD5_DIGEST_LENGTH + BITS_LEN] = {0}; uchar md5_src_2[(MD5_DIGEST_LENGTH << 1) + VERIFY_LEN] = {0}; uchar md5_src[MD5_DIGEST_LENGTH << 1] = {0}; size_t i; memcpy(md5_src_1, password_bin.ptr, MD5_DIGEST_LENGTH); memcpy(md5_src_1 + MD5_DIGEST_LENGTH, bits, BITS_LEN); str_free(password_bin); md5_str(md5_src_1, MD5_DIGEST_LENGTH + BITS_LEN, md5_src); memcpy(md5_src_2, md5_src, MD5_DIGEST_LENGTH << 1); for (i = 0; i < VERIFY_LEN; ++i) { md5_src_2[(MD5_DIGEST_LENGTH << 1) + i] = toupper(verify_code[i]); } md5_str(md5_src_2, (MD5_DIGEST_LENGTH << 1) + VERIFY_LEN, out); }
int callback(void *ud, const char *key, unsigned key_sz, const char *value, unsigned value_sz) { ud = ud; printf("hash=%s key=%.*s value=%.*s\n", md5_str(key, key_sz), key_sz, key, value_sz, value); return 0; }
string get_md5sum(string file_name) { FILE *fp; string command = "md5sum " + file_name; fp = popen(command.c_str(), "r"); char md5[100]; fscanf(fp,"%s", md5); fclose(fp); string md5_str(md5); return md5_str; }
static void encrypt() { unsigned char ch; unsigned char password[256]; int i; int err; unsigned char md5[MD5_DIGEST_LENGTH << 1]; struct termios term; if (tcgetattr(STDIN_FILENO, &term)==-1) { perror("Cannot get the attribution of the terminal"); return; } term.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL | ECHOPRT | ECHOKE | ICRNL); err = tcsetattr(STDIN_FILENO, TCSAFLUSH, &term); if (err == -1 && err == EINTR) { perror("Cannot set the attribution of the terminal"); return; } i = 0; fprintf(stdout, "Please input password:"); do { ch = getchar(); if (ch == '\n' || ch == '\r') break; if (ch == 127 && i > 0) --i; else { if (i >= 254) { fprintf(stderr, "Password length must less than 255!!!!\n"); return; } password[i++] = ch; } } while (1); fprintf(stdout, "\n"); password[i] = 0; md5_str(password, i, md5); fprintf(stdout, "%-32.32s\n", md5); }
/*--------------------------------------------------------------------------*/ int C2F(sci_getmd5) (char *fname, unsigned long fname_len) { int m1 = 0, n1 = 0; int mn = 0; int i = 0; char **Input_Matrix = NULL; char **Output_Matrix = NULL; Rhs = Max(Rhs, 0); CheckRhs(1, 2) ; CheckLhs(1, 1) ; if (Rhs == 1) { if (GetType(1) == sci_strings) { GetRhsVar(1, MATRIX_OF_STRING_DATATYPE, &m1, &n1, &Input_Matrix); mn = m1 * n1; Output_Matrix = (char**)MALLOC(sizeof(char*) * (mn)); if (Output_Matrix) { for (i = 0; i < mn; i++) { FILE *fp = NULL; char *MD5 = NULL; char *real_path = NULL; /* Replaces SCI, ~, HOME, TMPDIR by the real path */ real_path = expandPathVariable(Input_Matrix[i]); /* bug 4469 */ if (isdir(real_path)) { Scierror(999, _("%s: The file %s does not exist.\n"), fname, Input_Matrix[i]); freeArrayOfString(Output_Matrix, i); freeArrayOfString(Input_Matrix, mn); FREE(real_path); real_path = NULL; return 0; } wcfopen(fp, real_path, "rb"); if (real_path) { FREE(real_path); real_path = NULL; } if (fp) { MD5 = md5_file(fp); fclose(fp); Output_Matrix[i] = strdup(MD5); if (MD5) { FREE(MD5); MD5 = NULL; } } else { Scierror(999, _("%s: The file %s does not exist.\n"), fname, Input_Matrix[i]); freeArrayOfString(Output_Matrix, i); freeArrayOfString(Input_Matrix, mn); return 0; } } CreateVarFromPtr( Rhs + 1, MATRIX_OF_STRING_DATATYPE, &m1, &n1, Output_Matrix ); LhsVar(1) = Rhs + 1 ; PutLhsVar(); } else { Scierror(999, _("%s: Memory allocation error.\n"), fname); } } else { Scierror(999, _("%s: Wrong type of input argument #%d: String expected.\n"), fname, 1); } } else /* Rhs == 2 */ { if ( (GetType(1) == sci_strings) && (GetType(2) == sci_strings) ) { int m2 = 0, n2 = 0, l2 = 0; char *Param2 = NULL; GetRhsVar(1, MATRIX_OF_STRING_DATATYPE, &m1, &n1, &Input_Matrix); mn = m1 * n1; GetRhsVar(2, STRING_DATATYPE, &m2, &n2, &l2); Param2 = cstk(l2); if ( stricmp(Param2, "string") == 0 ) { Output_Matrix = (char**)MALLOC(sizeof(char*) * (mn)); if (Output_Matrix) { for (i = 0; i < mn; i++) { char *MD5 = NULL; MD5 = md5_str(Input_Matrix[i]); Output_Matrix[i] = strdup(MD5); if (MD5) { FREE(MD5); MD5 = NULL; } if (Output_Matrix[i] == NULL) { freeArrayOfString(Input_Matrix, m1 * n1); freeArrayOfString(Output_Matrix, i); Scierror(999, ("%s: No more memory.\n"), fname); return 0; } } CreateVarFromPtr(Rhs + 1, MATRIX_OF_STRING_DATATYPE, &m1, &n1, Output_Matrix ); LhsVar(1) = Rhs + 1 ; PutLhsVar(); } else { Scierror(999, _("%s: Memory allocation error.\n"), fname); } } else { Scierror(999, _("%s: Wrong value for input argument #%d: \"%s\" expected.\n"), fname, 2, "string"); } } else { Scierror(999, _("%s: Wrong type for input arguments #%d or #%d: Strings expected.\n"), fname, 1, 2); } } freeArrayOfString(Input_Matrix, mn); freeArrayOfString(Output_Matrix, mn); return 0; }