Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
onEncrypt = async () => {
try {
const { clearText, shareWith } = this.state;
const options = {};
if (shareWith) {
const publicIdentity = await this.fetchPublicIdentity(shareWith);
options.shareWithUsers = [publicIdentity];
}
this.log('encryption', clearText, shareWith);
const binary = await this.tanker.encrypt(clearText, options);
const base64 = toBase64(binary);
this.setState({
encryptedText: base64,
clearText: '',
shareWith: ''
});
this.log('encryptionSuccess', base64);
} catch (e) {
this.log(e);
}
}
async saveText(text) {
const recipients = await this.getNoteRecipients();
const recipientPublicIdentities = recipients.map((user) => user.publicIdentity);
const encryptedData = await this.tanker.encrypt(text, { shareWithUsers: recipientPublicIdentities });
const encryptedText = toBase64(encryptedData);
this.resourceId = await this.tanker.getResourceId(encryptedData);
await this.serverApi.push(encryptedText);
}