@@ -81,7 +81,8 @@ public function seal(string $name, string $value): void
8181 $ this ->lastMessage = null ;
8282 $ this ->validateName ($ name );
8383 $ this ->loadKeys ();
84- $ this ->export ($ name .'. ' .substr (md5 ($ name ), 0 , 6 ), sodium_crypto_box_seal ($ value , $ this ->encryptionKey ?? sodium_crypto_box_publickey ($ this ->decryptionKey )));
84+ $ filename = $ this ->getFilename ($ name );
85+ $ this ->export ($ filename , sodium_crypto_box_seal ($ value , $ this ->encryptionKey ?? sodium_crypto_box_publickey ($ this ->decryptionKey )));
8586
8687 $ list = $ this ->list ();
8788 $ list [$ name ] = null ;
@@ -96,7 +97,8 @@ public function reveal(string $name): ?string
9697 $ this ->lastMessage = null ;
9798 $ this ->validateName ($ name );
9899
99- if (!is_file ($ file = $ this ->pathPrefix .$ name .'. ' .substr_replace (md5 ($ name ), '.php ' , -26 ))) {
100+ $ filename = $ this ->getFilename ($ name );
101+ if (!is_file ($ file = $ this ->pathPrefix .$ filename .'.php ' )) {
100102 $ this ->lastMessage = sprintf ('Secret "%s" not found in "%s". ' , $ name , $ this ->getPrettyPath (\dirname ($ this ->pathPrefix ).\DIRECTORY_SEPARATOR ));
101103
102104 return null ;
@@ -130,7 +132,8 @@ public function remove(string $name): bool
130132 $ this ->lastMessage = null ;
131133 $ this ->validateName ($ name );
132134
133- if (!is_file ($ file = $ this ->pathPrefix .$ name .'. ' .substr_replace (md5 ($ name ), '.php ' , -26 ))) {
135+ $ filename = $ this ->getFilename ($ name );
136+ if (!is_file ($ file = $ this ->pathPrefix .$ filename .'.php ' )) {
134137 $ this ->lastMessage = sprintf ('Secret "%s" not found in "%s". ' , $ name , $ this ->getPrettyPath (\dirname ($ this ->pathPrefix ).\DIRECTORY_SEPARATOR ));
135138
136139 return false ;
@@ -194,16 +197,16 @@ private function loadKeys(): void
194197 }
195198 }
196199
197- private function export (string $ file , string $ data ): void
200+ private function export (string $ filename , string $ data ): void
198201 {
199- $ b64 = 'decrypt.private ' === $ file ? '// SYMFONY_DECRYPTION_SECRET= ' .base64_encode ($ data )."\n" : '' ;
200- $ name = basename ($ this ->pathPrefix .$ file );
202+ $ b64 = 'decrypt.private ' === $ filename ? '// SYMFONY_DECRYPTION_SECRET= ' .base64_encode ($ data )."\n" : '' ;
203+ $ name = basename ($ this ->pathPrefix .$ filename );
201204 $ data = str_replace ('% ' , '\x ' , rawurlencode ($ data ));
202205 $ data = sprintf ("<?php // %s on %s \n\n%sreturn \"%s \"; \n" , $ name , date ('r ' ), $ b64 , $ data );
203206
204207 $ this ->createSecretsDir ();
205208
206- if (false === file_put_contents ($ this ->pathPrefix .$ file .'.php ' , $ data , \LOCK_EX )) {
209+ if (false === file_put_contents ($ this ->pathPrefix .$ filename .'.php ' , $ data , \LOCK_EX )) {
207210 $ e = error_get_last ();
208211 throw new \ErrorException ($ e ['message ' ] ?? 'Failed to write secrets data. ' , 0 , $ e ['type ' ] ?? \E_USER_WARNING );
209212 }
@@ -217,4 +220,10 @@ private function createSecretsDir(): void
217220
218221 $ this ->secretsDir = null ;
219222 }
223+
224+ private function getFilename (string $ name ): string
225+ {
226+ // The MD5 hash allows making secrets case-sensitive. The filename is not enough on Windows.
227+ return $ name .'. ' .substr (md5 ($ name ), 0 , 6 );
228+ }
220229}
0 commit comments