MultiKeyWrapper.php in Lockr 7.2
File
vendor/lockr/lockr-client/src/KeyWrapper/MultiKeyWrapper.php
View source
<?php
namespace Lockr\KeyWrapper;
class MultiKeyWrapper implements KeyWrapperInterface {
protected static $wrappers = array(
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) {
foreach (self::$wrappers as $wrapper) {
if ($wrapper::enabled()) {
return $wrapper::encrypt($plaintext);
}
}
return false;
}
public static function decrypt($ciphertext, $encoded) {
foreach (self::$wrappers as $prefix => $wrapper) {
if (substr($encoded, 0, strlen($prefix)) === $prefix) {
return $wrapper::decrypt($ciphertext, $encoded);
}
}
return false;
}
public static function reencrypt($plaintext, $encoded) {
foreach (self::$wrappers as $prefix => $wrapper) {
if (substr($encoded, 0, strlen($prefix)) === $prefix) {
return $wrapper::reencrypt($plaintext, $encoded);
}
}
return false;
}
}