12
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CakePHP / Security.salt とは? Security.cipherSeed とは?

Last updated at Posted at 2015-10-27

Security.salt と Security.cipherSeed をソースコードから探してみた

CakePHP をインストールすると最初に設定する salt 値について、結局これってどこで使われているのというのがネット上にはあまりなかったので調べてみた。

Security.salt

UUID生成で使用

lib/Cake/Utility/CakeText.php:77
public static function uuid() {
  # 中略
		if (empty($node)) {
			$node = crc32(Configure::read('Security.salt'));
		}

hash関数で使用

hash関数のデフォルト salt になるようだ。

lib/Cake/Utility/Security.php:117
public static function hash($string, $type = null, $salt = false) {
  # 中略
		if ($salt) {
			if (!is_string($salt)) {
				$salt = Configure::read('Security.salt');
			}
			$string = $salt . $string;
		}

salt文字抜き出しで使用

lib/Cake/Utility/Security.php:250
/**
 * Generates a pseudo random salt suitable for use with php's crypt() function.
 * The salt length should not exceed 27. The salt will be composed of
 * [./0-9A-Za-z]{$length}.
 *
 * @param int $length The length of the returned salt
 * @return string The generated salt
 */
	protected static function _salt($length = 22) {
		$salt = str_replace(
			array('+', '='),
			'.',
			base64_encode(sha1(uniqid(Configure::read('Security.salt'), true), true))
		);
		return substr($salt, 0, $length);
	}

暗号化で使用

lib/Cake/Utility/Security.php:309
	public static function encrypt($plain, $key, $hmacSalt = null) {
		static::_checkKey($key, 'encrypt()');

		if ($hmacSalt === null) {
			$hmacSalt = Configure::read('Security.salt');
		}

復号化で使用

lib/Cake/Utility/Security.php:352
	public static function decrypt($cipher, $key, $hmacSalt = null) {
		static::_checkKey($key, 'decrypt()');
		if (empty($cipher)) {
			throw new CakeException(__d('cake_dev', 'The data to decrypt cannot be empty.'));
		}
		if ($hmacSalt === null) {
			$hmacSalt = Configure::read('Security.salt');
		}

Security.cipher

暗号化で使用

lib/Cake/Utility/Security.php:184
	public static function cipher($text, $key) {
		if (empty($key)) {
			trigger_error(__d('cake_dev', 'You cannot use an empty key for %s', 'Security::cipher()'), E_USER_WARNING);
			return '';
		}

		srand(Configure::read('Security.cipherSeed'));

結果

まあ、予想通りな感じで特に面白みのない結果に…。
ざっくりは以下のように捉えて全く問題なさそう。

CakePHP2 実践入門より

Security.salt と Security.cipherSeed は、CakePHP がパスワードや Cookie に保存する情報を、ハッシュ化や暗号化する際に利用されます。

12
16
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?