Created
January 3, 2019 22:42
-
-
Save matheusfaustino/5d5d7d4f07bc82024804d77ca931b6d6 to your computer and use it in GitHub Desktop.
POC: PHP + RSA + Front JS (JS Encrypt)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$rsaPriv = __DIR__ . '/priv.pem'; | |
$rsaPub = __DIR__ . '/pub.pem'; | |
if ($_SERVER['REQUEST_METHOD'] === 'POST') { | |
$encrypted = $_POST['pass']; | |
$ok = \openssl_private_decrypt(base64_decode($encrypted), $decrypted, file_get_contents($rsaPriv), OPENSSL_PKCS1_PADDING); | |
var_dump($decrypted, $ok); | |
} | |
?> | |
<html> | |
<head> | |
<title>JavaScript RSA Encryption</title> | |
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script> | |
<script src="jsencrypt-master/bin/jsencrypt.min.js" async defer></script> | |
<script type="text/javascript"> | |
$('document').ready(function () { | |
$('#form').submit(function () { | |
var encrypt = new JSEncrypt(); | |
encrypt.setKey(atob($('#pub').val())); | |
var encrypted = encrypt.encrypt($('#pass').val()); | |
// encrypted ja é em base64 | |
$('#pass').val(encrypted); | |
return true; | |
}); | |
}); | |
</script> | |
</head> | |
<body> | |
<form method="post" id="form"> | |
<label for="pass">Entre com a senha: </label> | |
<input type="hidden" value="<?=base64_encode(file_get_contents($rsaPub))?>" id="pub"> | |
<input type="password" name="pass" id="pass"/> | |
<input type="submit" value="Enviar" id="enviar"/> | |
<br/> | |
<p>Olha a requisição</p> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment