61 lines
1.4 KiB
PHP
61 lines
1.4 KiB
PHP
<?php
|
|
|
|
/*
|
|
* smzint/Messages (c) schmamazon.com 2025
|
|
*/
|
|
|
|
include('../Auth/index.php');
|
|
include('ready.php');
|
|
|
|
function grabPublicKey($uid){
|
|
global $dbservername;
|
|
global $dbusername;
|
|
global $dbpassword;
|
|
global $dbname;
|
|
$conn = new mysqli($dbservername, $dbusername, $dbpassword, $dbname);
|
|
if ($conn->connect_error) {
|
|
die("Connection failed: " . $conn->connect_error);
|
|
}
|
|
|
|
$sql = "SELECT publicKey FROM smz_messages_users WHERE uid='$uid'";
|
|
$result = $conn->query($sql);
|
|
if ($result->num_rows > 0) {
|
|
while($row = $result->fetch_assoc()) {
|
|
return $row["publicKey"];
|
|
}
|
|
} else {
|
|
return false;
|
|
}
|
|
$conn->close();
|
|
}
|
|
|
|
function grabPrivateKey($password){
|
|
global $dbservername;
|
|
global $dbusername;
|
|
global $dbpassword;
|
|
global $dbname;
|
|
global $uid;
|
|
global $upassword_hash;
|
|
if (!password_verify($password, $upassword_hash)){
|
|
echo "Passwortfehler";
|
|
return false;
|
|
}
|
|
$conn = new mysqli($dbservername, $dbusername, $dbpassword, $dbname);
|
|
if ($conn->connect_error) {
|
|
die("Connection failed: " . $conn->connect_error);
|
|
}
|
|
|
|
$sql = "SELECT privateKey, iv FROM smz_messages_users WHERE uid='$uid'";
|
|
$result = $conn->query($sql);
|
|
if ($result->num_rows > 0) {
|
|
while($row = $result->fetch_assoc()) {
|
|
return openssl_decrypt(base64_decode($row["privateKey"]), 'aes-128-cbc', $password, 0, base64_decode($row["iv"]));
|
|
}
|
|
} else {
|
|
return false;
|
|
}
|
|
$conn->close();
|
|
}
|
|
|
|
|
|
?>
|