Provides a Utility to construct and handle encryption for Commet's encrypted url previews.
This is still experimental and should not be used in a production project.
This package is intended to be used in conjunction with a matrix client.
final encryptedPreviewGetter = EncryptedUrlPreview(
proxyServerUrl: Uri.parse("https://telescope.commet.chat"),
// Server public key
publicKeyPem: """-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAz+sAi8PsT4QwjV/+xXK0
vwavZJEjkwJyFODGWkoo7qB87Y2yU6/C4csul6kQpxBFu9ID7mCavAlr93/c70Qm
sgX791W7oOSpvyeffJe5iluzaglZ/KWYo6Bc0QajKT8rLdI5vUljVMyx/nR9rIhY
PvSJhSFLC2ZyUhhTb/ZeLm0arEtGeyfo1V3nLGsJZJx12UK8E0FpKP14S7Wke9zM
e05PDCU/llEQpUgQOJI9Vnji71Fgocii76aSULhXalGjQIzBGKib5MIYlb0Zgf8k
wKkRg6IrNt5kjad4PoRKocxj3ylvuxEtMN582ni3lO4gi1uzzVvFtJBzrhNMjTPC
pQIDAQAB
-----END PUBLIC KEY-----""");
var contentKey = urlGetter.getNextKey();
var proxyUrl = encryptedPreviewGetter!.getProxyUrl(url, contentKey);
var response = await client.request(
matrix.RequestType.GET, "/media/v3/preview_url",
query: {"url": proxyUrl.toString()});
var title = response['og:title'] as String?;
var imageUrl = response['og:image'] as String?;
ImageProvider? image;
if (imageUrl != null) {
var mxcUri = Uri.parse(imageUrl);
if (mxcUri.scheme == "mxc") {
var response =
await client.httpClient.get(mxcUri.getDownloadLink(client));
var bytes = response.bodyBytes;
var decrypted = encryptedPreviewGetter!.decryptContent(bytes, contentKey);
image = Image.memory(decrypted).image;
}
}
if (title != null)
title = encryptedPreviewGetter!.decryptContentString(title, contentKey);
See ABOUT.md