@@ -81,15 +81,17 @@ int crypto_import_aes_key
81
81
size_t objIDLen
82
82
)
83
83
{
84
- const size_t cMaxAesKeySize = 1024 + 1 ; // including null-character
84
+ const size_t cMaxAesKeySize = 1024 ;
85
85
char aesKeyValue[cMaxAesKeySize];
86
+ size_t aesKeyLength = 0 ;
86
87
FILE* fp = fopen (filePath, " rb" );
87
88
if (fp == NULL )
88
89
{
89
90
fprintf (stderr, " ERROR: Could not open the secret key file.\n " );
90
91
return 1 ;
91
92
}
92
- if (fgets (aesKeyValue, cMaxAesKeySize, fp) == NULL )
93
+ aesKeyLength = fread (aesKeyValue, 1 , cMaxAesKeySize, fp);
94
+ if (aesKeyLength == 0 )
93
95
{
94
96
fprintf (stderr, " ERROR: Could not read the secret key file.\n " );
95
97
fclose (fp);
@@ -109,7 +111,7 @@ int crypto_import_aes_key
109
111
{ CKA_ENCRYPT, &ckTrue, sizeof (ckTrue) },
110
112
{ CKA_DECRYPT, &ckTrue, sizeof (ckTrue) },
111
113
{ CKA_SENSITIVE, &ckTrue, sizeof (ckTrue) },
112
- { CKA_VALUE, &aesKeyValue, strlen (aesKeyValue) }
114
+ { CKA_VALUE, &aesKeyValue, aesKeyLength }
113
115
};
114
116
115
117
CK_OBJECT_HANDLE hKey;
0 commit comments