This commit is contained in:
Luke Ogburn
2019-04-08 22:15:45 -04:00
commit 2ad617d74a
5 changed files with 74 additions and 0 deletions

6
download.php Normal file
View File

@@ -0,0 +1,6 @@
<?php
$content = "content and things like it are here";
header('Content-type: text/plain');
header('Content-Disposition: attachment; filename="encrypted.txt"');
echo $content;
?>

17
enc.php Normal file
View File

@@ -0,0 +1,17 @@
<?php
function encrypt($plaintext, $key){
$cipher = "aes-128-gcm";
if (in_array($cipher, openssl_get_cipher_methods())){
$ivlen = openssl_cipher_iv_length($cipher);
$iv = openssl_random_pseudo_bytes($ivlen);
$res = openssl_encrypt($plaintext, $cipher, $key, $options=0, $iv, $tag);
return array($res, $iv, $tag);
}
}
function decrypt($ciphertext, $key, $iv, $tag){
$cipher = "aes-128-gcm";
if (in_array($cipher, openssl_get_cipher_methods())){
return openssl_decrypt($ciphertext, $cipher, $key, $options=0, $iv, $tag);
}
}
?>

36
index.php Normal file
View File

@@ -0,0 +1,36 @@
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<title>Encrytion and stuff</title>
<meta name="viewport" content=width=device-width,initial-scale=1.0>
<link rel=stylesheet href=write.css type=text/css>
</head>
<body>
<script>
function wordCount(thing) {
regex = /(\S\s)|(([A-Z]|[a-z])(\.|\!|\?|\z))/;
numOfParenthesis = 5; //how many par. sets are in the regex
wordsLeft = 500-((thing.value.split(regex).length-1)/numOfParenthesis);
//if(wordsLeft<0){
// wordsLeft = 0;
//}
//Include if the counter shouldn't go below 0
document.getElementById("counter").innerHTML = wordsLeft;
if(wordsLeft<=0){
document.getElementById("submitWriting").disabled = false;
}else{
document.getElementById("submitWriting").disabled = true;
}
}
</script>
<form action=submit.php method=POST>
<h2 id=counter>500</h2>
<textarea onkeyup=wordCount(this) placeholder='Write your words here...' name=words></textarea>
<div id=writeButtons>
<button type=submit name=submit value=save id=saveWriting>SAVE</button>
<button type=submit name=submit value=submit id=submitWriting disabled>SUBMIT</button>
</div>
</form>
</body>
</html>

15
submit.php Normal file
View File

@@ -0,0 +1,15 @@
<?php
require $root."enc.php";
$enc = encrypt($_POST["words"], $current_key);
$postID = bin2hex(openssl_random_pseudo_bytes(7));
$stmt = $conn->prepare("INSERT INTO posts (id, user_id, text, iv, tag) VALUES (:id, :uid, :txt, :iv, :tag)");
$stmt->bindParam(":id", $postID);
$stmt->bindParam(":uid", $current_userID);
$stmt->bindParam(":txt", $enc[0]);
$stmt->bindParam(":iv", $enc[1]);
$stmt->bindParam(":tag", $enc[2]);
$stmt->execute();
header("Location: /500/read/?post=".$postID);
?>

0
write.css Normal file
View File