Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4096493
EncryptedData.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
EncryptedData.php
View Options
<?php
namespace
MediaWiki\CheckUser
;
class
EncryptedData
{
/** @var string|null The data symmetrically encrypted with a random key */
public
$encString
;
/** @var string|null Symmetric key, encrypted with the public key */
public
$envKeys
;
/**
* @var string algorithm name, passed into openssl 'method' param. Kept as a variable here in case
* the class definition needs to change, and we have serialized objects stored.
*/
private
$algName
;
/**
* @var int Hash of the public key, in case you've used multiple keys, and need to identify the
* correct private key
*/
private
$keyHash
;
/**
* Create an EncryptedData object from
*
* @param mixed $data Data/object to be encryted
* @param string $publicKey Public key for encryption
* @param string $algorithmName
*/
public
function
__construct
(
$data
,
$publicKey
,
$algorithmName
=
'rc4'
)
{
$this
->
keyHash
=
crc32
(
$publicKey
);
$this
->
algName
=
$algorithmName
;
$this
->
encryptData
(
serialize
(
$data
),
$publicKey
);
}
/**
* Decrypt the text in this object
*
* @param string $privateKey String with ascii-armored block,
* or the return of openssl_get_privatekey
* @return string|false plaintext
*/
public
function
getPlaintext
(
$privateKey
)
{
$result
=
\openssl_open
(
$this
->
encString
,
$plaintextData
,
$this
->
envKeys
,
$privateKey
,
$this
->
algName
);
if
(
!
$result
)
{
return
false
;
}
return
unserialize
(
$plaintextData
);
}
/**
* Encrypt data with a public key
*
* @param string $data
* @param string $publicKey String with ascii-armored block,
* or the return of openssl_get_publickey
*/
private
function
encryptData
(
$data
,
$publicKey
)
{
// @phan-suppress-next-line PhanTypeMismatchArgumentInternal
\openssl_seal
(
$data
,
$encryptedString
,
$envelopeKeys
,
[
$publicKey
],
$this
->
algName
);
$this
->
encString
=
$encryptedString
;
// @phan-suppress-next-line PhanTypeArraySuspiciousNullable
$this
->
envKeys
=
$envelopeKeys
[
0
];
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Tue, Aug 18, 14:22 (4 w, 2 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
d9/ad/ca47a727aca50f58feaf68e5dc2d
Default Alt Text
EncryptedData.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment