I'm opening this issue to gather code samples showing how to encode or decode the lcp_hashed_passphrase key as described in Readium LCP Automatic Key Retrieval.
Encoding
PHP
Courtesy of the Internet Archive.
$lcpHashedPassphrase = base64_encode(hash('sha256', $passphrase, true));
Decoding
Kotlin
Vanilla JVM
import java.util.Base64
val passphrase = Base64.getDecoder().decode(lcpHashedPassphrase)
.map { String.format("%02x", it) }
.joinToString(separator = "")
Android
import android.util.Base64
val passphrase = Base64.decode(lcpHashedPassphrase, Base64.DEFAULT)
.map { String.format("%02x", it) }
.joinToString(separator = "")
Swift
let passphrase = Data(base64Encoded: lcpHashedPassphrase)
.map { [UInt8]($0) }?
.map { String(format: "%02x", $0) }
.joined() ?? self
I'm opening this issue to gather code samples showing how to encode or decode the
lcp_hashed_passphrasekey as described in Readium LCP Automatic Key Retrieval.Encoding
PHP
Courtesy of the Internet Archive.
Decoding
Kotlin
Vanilla JVM
Android
Swift