@@ -449,6 +449,7 @@ class AtAuthServiceImpl implements AtAuthService {
449
449
var privateKeyCommand =
450
450
'keys:get:keyName:$enrollmentIdFromServer .${AtConstants .defaultEncryptionPrivateKey }.__manage$_atSign \n ' ;
451
451
String encryptionPrivateKeyFromServer;
452
+ String ? encryptionPrivateKeyIV;
452
453
try {
453
454
var getPrivateKeyResult =
454
455
await _atLookUp? .executeCommand ('$privateKeyCommand \n ' , auth: true );
@@ -458,13 +459,17 @@ class AtAuthServiceImpl implements AtAuthService {
458
459
getPrivateKeyResult = getPrivateKeyResult.replaceFirst ('data:' , '' );
459
460
var privateKeyResultJson = jsonDecode (getPrivateKeyResult);
460
461
encryptionPrivateKeyFromServer = privateKeyResultJson['value' ];
462
+ encryptionPrivateKeyIV = privateKeyResultJson['iv' ];
461
463
} on Exception catch (e) {
462
464
throw AtEnrollmentException (
463
465
'Exception while getting encrypted private key/self key from server: $e ' );
464
466
}
465
467
AtEncryptionResult ? atEncryptionResult = atChops.decryptString (
466
468
encryptionPrivateKeyFromServer, EncryptionKeyType .aes256,
467
- keyName: 'apkamSymmetricKey' , iv: AtChopsUtil .generateIVLegacy ());
469
+ keyName: 'apkamSymmetricKey' ,
470
+ iv: encryptionPrivateKeyIV != null
471
+ ? InitialisationVector (base64Decode (encryptionPrivateKeyIV))
472
+ : AtChopsUtil .generateIVLegacy ());
468
473
return atEncryptionResult.result;
469
474
}
470
475
@@ -476,6 +481,7 @@ class AtAuthServiceImpl implements AtAuthService {
476
481
var selfEncryptionKeyCommand =
477
482
'keys:get:keyName:$enrollmentIdFromServer .${AtConstants .defaultSelfEncryptionKey }.__manage$_atSign \n ' ;
478
483
String selfEncryptionKeyFromServer;
484
+ String ? selfEncryptionKeyIV;
479
485
try {
480
486
String ? encryptedSelfEncryptionKey = await _atLookUp
481
487
? .executeCommand ('$selfEncryptionKeyCommand \n ' , auth: true );
@@ -488,13 +494,17 @@ class AtAuthServiceImpl implements AtAuthService {
488
494
encryptedSelfEncryptionKey.replaceFirst ('data:' , '' );
489
495
var selfEncryptionKeyResultJson = jsonDecode (encryptedSelfEncryptionKey);
490
496
selfEncryptionKeyFromServer = selfEncryptionKeyResultJson['value' ];
497
+ selfEncryptionKeyIV = selfEncryptionKeyResultJson['iv' ];
491
498
} on Exception catch (e) {
492
499
throw AtEnrollmentException (
493
500
'Exception while getting encrypted private key/self key from server: $e ' );
494
501
}
495
502
AtEncryptionResult ? atEncryptionResult = atChops.decryptString (
496
503
selfEncryptionKeyFromServer, EncryptionKeyType .aes256,
497
- keyName: 'apkamSymmetricKey' , iv: AtChopsUtil .generateIVLegacy ());
504
+ keyName: 'apkamSymmetricKey' ,
505
+ iv: selfEncryptionKeyIV != null
506
+ ? InitialisationVector (base64Decode (selfEncryptionKeyIV))
507
+ : AtChopsUtil .generateIVLegacy ());
498
508
return atEncryptionResult.result;
499
509
}
500
510
0 commit comments