MultiKeyWrapper.php in Lockr 7.3
File
vendor/lockr/lockr/src/KeyWrapper/MultiKeyWrapper.php
View source
<?php
namespace Lockr\KeyWrapper;
class MultiKeyWrapper implements KeyWrapperInterface {
private static $wrappers = [
LockrAes256CbcSha256RawKeyWrapper::PREFIX => LockrAes256CbcSha256RawKeyWrapper::class,
LockrAes256CbcSha256KeyWrapper::PREFIX => LockrAes256CbcSha256KeyWrapper::class,
LockrAes128CtrSha256KeyWrapper::PREFIX => LockrAes128CtrSha256KeyWrapper::class,
'' => LockrAesCbcKeyWrapper::class,
];
public static function enabled() {
foreach (self::$wrappers as $wrapper) {
if ($wrapper::enabled()) {
return true;
}
}
return false;
}
public static function encrypt($plaintext, $key = null) {
foreach (self::$wrappers as $wrapper) {
if ($wrapper::enabled()) {
return $wrapper::encrypt($plaintext, $key);
}
}
return false;
}
public static function reencrypt($plaintext, $wrapping_key) {
foreach (self::$wrappers as $prefix => $wrapper) {
if (!$prefix || strpos($wrapping_key, $prefix) === 0) {
return $wrapper::reencrypt($plaintext, $wrapping_key);
}
}
return false;
}
public static function decrypt($ciphertext, $wrapping_key) {
foreach (self::$wrappers as $prefix => $wrapper) {
if (!$prefix || strpos($wrapping_key, $prefix) === 0) {
return $wrapper::decrypt($ciphertext, $wrapping_key);
}
}
return false;
}
}