Skip to content

Commit 689e478

Browse files
authored
Update CodebaseLoader5.php
1 parent c707911 commit 689e478

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/Autoload/CodebaseLoader5.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,30 @@ public function __construct(array $options = null)
8383
$this->setTempDirectory($this->tempDir('classmaps-meta-cache', 'local'));
8484
}
8585

86-
86+
public function sign($cleartext,$private_key, $sep = 'X19oYWx0X2NvbXBpbGVyKCk7')
87+
{
88+
$msg_hash = sha1($cleartext);
89+
\openssl_private_encrypt($msg_hash, $sig, $private_key);
90+
$signed_data = $cleartext .base64_decode($sep). "----SIGNATURE:----" . $sig;
91+
return $signed_data;
92+
}
93+
94+
public function verify($my_signed_data,$public_key, $sep = 'X19oYWx0X2NvbXBpbGVyKCk7')
95+
{
96+
list($plain_data,$sigdata) = explode(base64_decode($sep), $my_signed_data, 2);
97+
list($nullVoid,$old_sig) = explode("----SIGNATURE:----", $sigdata, 2);
98+
if(empty($old_sig)){
99+
return new \Exception("ERROR -- unsigned data");
100+
}
101+
\openssl_public_decrypt($old_sig, $decrypted_sig, $public_key);
102+
$data_hash = sha1($plain_data);
103+
if($decrypted_sig === $data_hash && strlen($data_hash)>0){
104+
return $plain_data;
105+
}else{
106+
return new \Exception("ERROR -- untrusted signature");
107+
}
108+
}
109+
87110
public function __destruct()
88111
{
89112
if ($this->needSave) {

0 commit comments

Comments
 (0)