decrypt method

  1. @override
void decrypt(
  1. String password
)
override

Decrypts this entry using the given password.

Implementation

@override
void decrypt(String password) {
  if (isDecrypted()) return;

  try {
    final protectedKey = encryptedDataBytes!;
    final Uint8List plaintext;
    if (protectedKey.isNotEmpty && protectedKey[0] == 0x30) {
      // EncryptedPrivateKeyInfo, in JKS and in JCEKS: the OID says which.
      final top = _DerReader(protectedKey).readSequence();
      final oid = top.readSequence().readOid();
      if (oid == _jksKeyProtectorOid) {
        plaintext = _jksRecover(top.readOctetString(), password,
            digestEncrypted: false);
      } else if (oid == _jceksKeyProtectorOid) {
        plaintext = _jceksDecrypt(protectedKey, password);
      } else {
        throw DecryptionFailureException(
            'Unsupported key protection algorithm: $oid');
      }
    } else {
      // Written by pdf_plus before 4.0.2: no EncryptedPrivateKeyInfo and
      // the integrity digest XORed together with the key.
      plaintext = _jksRecover(protectedKey, password, digestEncrypted: true);
    }

    pkcs8PrivateKey = plaintext;
    rawPrivateKey = _privateKeyOctets(plaintext) ?? plaintext;
    encryptedDataBytes = null;
  } catch (e) {
    if (e is KeystoreException) rethrow;
    throw DecryptionFailureException('Decryption failed: $e');
  }
}