一切正常,我只想用以下示例从数据库中解密包含信用卡号的db列:
$decp = $crypt->decrypt($encp);
有问题的行是:
'Number' => $row['cardNumber'],
整个代码是:
// get the cards
$jsonresult = $conn->query("SELECT nameOnCard, cardNumber, cardType, cardDate, ccvCode
FROM cy_user_credit_cards
WHERE accountNumber='$accountNumber'");
$creditCard = [];
while ($row = mysqli_fetch_assoc($jsonresult)) {
array_push($creditCard, [
'Name' => $row['nameOnCard'],
'Number' => $row['cardNumber'],
'Type' => $row['cardType'],
'Date' => $row['cardDate'],
'ccv' => $row['ccvCode']
]);
}
// Convert the Array to a JSON String and echo it
$ccJSON = json_encode($creditCard);
echo $ccJSON;
$conn->close();
最佳答案
我想您会想做这样的事情:
// get the cards
$jsonresult = $conn->query("SELECT nameOnCard, cardNumber, cardType, cardDate, ccvCode
FROM cy_user_credit_cards
WHERE accountNumber='$accountNumber'");
$creditCard = [];
while ($row = mysqli_fetch_assoc($jsonresult)) {
array_push($creditCard, [
'Name' => $row['nameOnCard'],
'Number' => $crypt->decrypt($row['cardNumber']),
'Type' => $row['cardType'],
'Date' => $row['cardDate'],
'ccv' => $row['ccvCode']
]);
}
// Convert the Array to a JSON String and echo it
$ccJSON = json_encode($creditCard);
echo $ccJSON;
$conn->close();
请记住,如果并非绝对必要,那么您真的不想将所有这些信用卡详细信息存储在数据库中。我敦促您到其他地方去处理信用卡付款。
关于php - PHP MySQL:从MySQL行中解密列值,该列值在插入时已加密并解析为JSON,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31305781/