Browse Source

crypto getSecretKey

frederic 3 years ago
parent
commit
494134f7c1
1 changed files with 10 additions and 6 deletions
  1. 10
    6
      Crypto/Crypto.php

+ 10
- 6
Crypto/Crypto.php View File

@@ -6,8 +6,12 @@ class Crypto
6 6
     // Clef de cryptage
7 7
     private static $key = "ClefLogipro";
8 8
     private static $salt = "";
9
-
10
-    private static $secretKey = null;
9
+/**
10
+ * clef arbitraire de 32 bits
11
+ *
12
+ * @var string
13
+ */
14
+    private static $secretKey = "7e4oG8RgOqGEzGtPWtlNAfI8cWgBmeSo";
11 15
 
12 16
     public static function crypt($data)
13 17
     {
@@ -36,10 +40,10 @@ class Crypto
36 40
     {
37 41
         $decoded = base64_decode($data);
38 42
         if ($decoded === false) {
39
-            throw new Exception('The encoding failed');
43
+            throw new \Exception('The encoding failed');
40 44
         }
41 45
         if (mb_strlen($decoded, '8bit') < (SODIUM_CRYPTO_SECRETBOX_NONCEBYTES + SODIUM_CRYPTO_SECRETBOX_MACBYTES)) {
42
-            throw new Exception('The message was truncated');
46
+            throw new \Exception('The message was truncated');
43 47
         }
44 48
 
45 49
         $nonce = mb_substr($decoded, 0, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, '8bit');
@@ -52,7 +56,7 @@ class Crypto
52 56
             $secretKey
53 57
         );
54 58
         if ($plain === false) {
55
-            throw new Exception('The message was tampered with in transit');
59
+            throw new \Exception('The message was tampered with in transit');
56 60
         }
57 61
         
58 62
         sodium_memzero($ciphertext);
@@ -62,7 +66,7 @@ class Crypto
62 66
     }
63 67
 
64 68
     /**
65
-     * calcul et renvoi une clef de la durée de vie du script
69
+     * renvoi une clef de la durée de vie du script
66 70
      *
67 71
      * @return string clef de 32 bytes
68 72
      */

Loading…
Cancel
Save