@@ -81,15 +81,17 @@ int crypto_import_aes_key
8181 size_t objIDLen
8282)
8383{
84- const size_t cMaxAesKeySize = 1024 + 1 ; // including null-character
84+ const size_t cMaxAesKeySize = 1024 ;
8585 char aesKeyValue[cMaxAesKeySize];
86+ size_t aesKeyLength = 0 ;
8687 FILE * fp = fopen (filePath, " rb" );
8788 if (fp == NULL )
8889 {
8990 fprintf (stderr, " ERROR: Could not open the secret key file.\n " );
9091 return 1 ;
9192 }
92- if (fgets (aesKeyValue, cMaxAesKeySize, fp) == NULL )
93+ aesKeyLength = fread (aesKeyValue, 1 , cMaxAesKeySize, fp);
94+ if (aesKeyLength == 0 )
9395 {
9496 fprintf (stderr, " ERROR: Could not read the secret key file.\n " );
9597 fclose (fp);
@@ -109,7 +111,7 @@ int crypto_import_aes_key
109111 { CKA_ENCRYPT , &ckTrue, sizeof (ckTrue) },
110112 { CKA_DECRYPT , &ckTrue, sizeof (ckTrue) },
111113 { CKA_SENSITIVE , &ckTrue, sizeof (ckTrue) },
112- { CKA_VALUE , &aesKeyValue, strlen (aesKeyValue) }
114+ { CKA_VALUE , &aesKeyValue, aesKeyLength }
113115 };
114116
115117 CK_OBJECT_HANDLE hKey;
0 commit comments