|
@@ -7,6 +7,8 @@ class Crypto
|
7
|
7
|
private static $key = "ClefLogipro";
|
8
|
8
|
private static $salt = "";
|
9
|
9
|
|
|
10
|
+ private static $secretKey = null;
|
|
11
|
+
|
10
|
12
|
public static function crypt($data)
|
11
|
13
|
{
|
12
|
14
|
$secretKey = self::getSecretKey();
|
|
@@ -59,20 +61,21 @@ class Crypto
|
59
|
61
|
return $plain;
|
60
|
62
|
}
|
61
|
63
|
|
62
|
|
- protected static function getSecretKey()
|
|
64
|
+ /**
|
|
65
|
+ * calcul et renvoi une clef de la durée de vie du script
|
|
66
|
+ *
|
|
67
|
+ * @return string clef de 32 bytes
|
|
68
|
+ */
|
|
69
|
+ protected static function getSecretKey() : string
|
63
|
70
|
{
|
64
|
|
- if (empty(self::$salt)) {
|
65
|
|
- self::$salt = \mb_substr("GHXVV706DHYGYROUGZDVQ9FGQVU8ZG6KQCZ1BPUWM6OFHDHLXERCTBVHSLBFXM7F", 0, SODIUM_CRYPTO_PWHASH_SALTBYTES, '8bit');
|
|
71
|
+ if (self::$secretKey !=null) {
|
|
72
|
+ return self::$secretKey;
|
66
|
73
|
}
|
67
|
|
- $secretKey = \sodium_crypto_pwhash(
|
68
|
|
- 32,
|
69
|
|
- self::$key,
|
70
|
|
- self::$salt,
|
71
|
|
- SODIUM_CRYPTO_PWHASH_OPSLIMIT_MODERATE,
|
72
|
|
- SODIUM_CRYPTO_PWHASH_MEMLIMIT_MODERATE,
|
73
|
|
- SODIUM_CRYPTO_PWHASH_ALG_DEFAULT
|
74
|
|
- );
|
75
|
|
-
|
76
|
|
- return $secretKey;
|
|
74
|
+ $chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
75
|
+ self::$secretKey = '';
|
|
76
|
+ for ($i=0; $i<32; $i++) {
|
|
77
|
+ self::$secretKey .= $chars[rand(0, strlen($chars)-1)];
|
|
78
|
+ }
|
|
79
|
+ return self::$secretKey;
|
77
|
80
|
}
|
78
|
81
|
}
|