This repository has been archived on 2022-12-28. You can view files and clone it, but cannot push or open issues or pull requests.
apiOld/old/crypt/encrypt/api.php
2021-01-01 15:48:55 +08:00

90 lines
2.7 KiB
PHP

<?php
header("Content-type:text/html;charset=utf-8");
$db=mysqli_connect("localhost","ghinkapi","ghink2014","ghinkapi");
mysqli_query($db,"set names utf8");
if($_GET['type']==""){
if($_POST['text']!=""){
if($_GET['text']!=""){
header("Content-type:application/json");
echo '{"error":"10000"}';
$encrypt_result=false;
}else{
$encrypt_result=md5($_POST['text']);
$unencrypted=$_POST['text'];
}
}else{
if($_GET['text']!=""){
$encrypt_result=md5($_GET['text']);
$unencrypted=$_GET['text'];
}else{
header("Content-type:application/json");
echo '{"error":"10001"}';
$encrypt_result=false;
}
}
if($encrypt_result!=false){;
echo $encrypt_result;
$result=mysqli_query($db,"SELECT `unencrypted` FROM `crypt_md5` WHERE `unencrypted`='".$unencrypted."'");
if(empty(mysqli_fetch_array($result))){
mysqli_query($db,"INSERT INTO `crypt_md5` (`unencrypted`, `encrypted`) VALUES ('".$unencrypted."', '".$encrypt_result."')");
}
}
}elseif($_GET['type']=="md5"){
if($_POST['text']!=""){
if($_GET['text']!=""){
header("Content-type:application/json");
echo '{"error":"10000"}';
$encrypt_result=false;
}else{
$encrypt_result=md5($_POST['text']);
$unencrypted=$_POST['text'];
}
}else{
if($_GET['text']!=""){
$encrypt_result=md5($_GET['text']);
$unencrypted=$_GET['text'];
}else{
header("Content-type:application/json");
echo '{"error":"10001"}';
$encrypt_result=false;
}
}
if($encrypt_result!=false){
echo $encrypt_result;
$result=mysqli_query($db,"SELECT `unencrypted` FROM `crypt_md5` WHERE `unencrypted`='".$unencrypted."'");
if(empty(mysqli_fetch_array($result))){
mysqli_query($db,"INSERT INTO `crypt_md5` (`unencrypted`, `encrypted`) VALUES ('".$unencrypted."', '".$encrypt_result."')");
}
}
}elseif($_GET['type']=="sha1"){
if($_POST['text']!=""){
if($_GET['text']!=""){
header("Content-type:application/json");
echo '{"error":"10000"}';
$encrypt_result=false;
}else{
$encrypt_result=sha1($_POST['text']);
$unencrypted=$_POST['text'];
}
}else{
if($_GET['text']!=""){
$encrypt_result=sha1($_GET['text']);
$unencrypted=$_GET['text'];
}else{
header("Content-type:application/json");
echo '{"error":"10001"}';
$encrypt_result=false;
}
}
if($encrypt_result!=false){
echo $encrypt_result;
$result=mysqli_query($db,"SELECT `unencrypted` FROM `crypt_sha1` WHERE `unencrypted`='".$unencrypted."'");
if(empty(mysqli_fetch_array($result))){
mysqli_query($db,"INSERT INTO `crypt_sha1` (`unencrypted`, `encrypted`) VALUES ('".$unencrypted."', '".$encrypt_result."')");
}
}
}else{
header("Content-type:application/json");
echo '{"error":"10004"}';
}
mysqli_close($db);