added Container.decryptWithPassword
This commit is contained in:
parent
ca9ab0f7a0
commit
3bd06ac7ff
@ -321,6 +321,27 @@ sealed class Container {
|
||||
}.build()
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrypt the container with a password. It scans all key ids for
|
||||
* these with `KDP` params, e.g., derived from password, and try to
|
||||
* derive keys from the password and decrypt the container. If there are
|
||||
* no derivable keys, or all of them failed to decrypt, returns null.
|
||||
* It could be long operation if there are multiple derivable keys with heavy
|
||||
* KDF. See [PBKD] and [KDF] for more.
|
||||
*
|
||||
* @return decrypted data or null
|
||||
*/
|
||||
@Suppress("unused")
|
||||
fun decryptWithPassword(password: String): UByteArray? {
|
||||
for( id in this.keyIds ) {
|
||||
id.kdp?.let { kdp ->
|
||||
decryptWith(kdp.deriveKey(password))?.let { return it }
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
companion object {
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user