我正在尝试在sqlLite数据库中保存加密数据。因此,当输入的数据被加密时,某些字符可能会变为'字符,从而阻止在数据库中插入记录。
现在,问题更加严重,因为我无法通过在加密文本中找到它来逃避角色,因为如果我逃脱角色,那么在解密期间输出文本将被破坏。
char sql[] = "INSERT INTO ";
//strcpy(sql, "INSERT INTO ");
strcat(sql, _TABLE_NAME_VALUE);
strcat(sql, "(");
strcat(sql, _source_id_value);
strcat(sql, ",");
strcat(sql, _command_id_value);
strcat(sql, ",");
strcat(sql, _fingerprint_value);
strcat(sql, ",");
strcat(sql, _app_id_value);
strcat(sql, ",");
strcat(sql, _rule_type_value);
strcat(sql, ")");
strcat(sql, " VALUES (");
strcat(sql, "'");
strcat(sql, encryptSourceId);
strcat(sql, "'");
strcat(sql, ",");
char temp[1000];
//itoa(commandIdInt,temp,10);
//LOGD("Temp value is: %s", temp);
sprintf(temp, "%s%d",sql, commandId);
LOGD("Temp value is: %s", temp);
LOGD("SQL command before copy is: %s", sql);
strcpy(sql, temp);
LOGD("SQL command after copy is: %s", sql);
strcat(sql, ",");
//strcat(sql, commandId);
//strcat(sql, ",");
strcat(sql, "'");
strcat(sql, encryptFingerPrint);
strcat(sql, "'");
strcat(sql, ",");
strcat(sql, "'");
strcat(sql, encryptAppId);
strcat(sql, "'");
strcat(sql, ",");
strcat(sql, "'");
strcat(sql, encryptRuleType);
strcat(sql, "'");
strcat(sql, ")");
LOGD("SQL Insert Query is: %s", sql);
//char *name = "Name";
//char *fullname = "My " name;
//LOGD("%s",fullname);
// Execute SQL Statement
//rc = sqlite3_exec(db, sql, callback, 0, &zErrMsg);
rc = sqlite3_exec(db, sql, NULL, NULL, &zErrMsg);
if(sqlite3_exec(db, sql, NULL, NULL, &zErrMsg)!= SQLITE_OK) {
//fprint(stderr, "SQL error: %s\n", zErrMsg);
LOGD("SQL Error is: %s\n", zErrMsg);
LOGD("INSERT TABLE FAILED");
//throw_sqlite3_exception(env, db);
sqlite3_free(zErrMsg);
}
else
{
fprintf(stdout, "Table Created Successfully\n");
LOGD("Table Created Successfully");
}
注意:我正在使用RSA算法和JNI进行上述所有操作。
请帮助!!!
答案 0 :(得分:2)
加密文本不再是文本,而是一堆原始字节,因此将其存储在CHAR
风格的数据库字段中是不可行的。
为了存储(病名)密文,你基本上有两个选择:
LOB
- 类型列CHAR
类型的列中无论哪种方式,你都不应该通过字符串组合来编写数据库语句,而是使用某种PreparedStatement
代替 - 所以你不会容易受到SQL注入攻击,也不必担心字符-escaping。