This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<head> | |
<link href="https://sdk.virtru.com/js/latest/auth-widget/index.css" rel="stylesheet"/> | |
<script src="https://sdk.virtru.com/js/latest/auth-widget/index.js"></script> | |
<script src="https://sdk.virtru.com/js/latest/virtru-sdk.min.js"></script> | |
</head> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<body> | |
<div id="virtru-auth-widget-mount"></div> | |
<script type="text/javascript"> | |
async function afterAuth(email) { | |
// Run all client code from here. | |
// This will only be called when the user is successfully authenticated. | |
const client = new Virtru.Client({email}); | |
const yourString = prompt('Type a sting to encrypt: ', 'Hello, world!'); | |
const encryptParams = new Virtru.EncryptParamsBuilder() | |
.withStringSource(yourString) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createPDF() { | |
var docBlob = DocumentApp.getActiveDocument().getBlob(); | |
docBlob.setName(doc.getName() + '.pdf'); | |
var blobB64 = Utilities.base64Encode(docBlob.getBytes()); | |
return blobB64; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Runs server-side function to return the contents | |
* of the document in base64 format. | |
* | |
* @return {string} Base 64'd document content. | |
*/ | |
function genPDF() { | |
return new Promise(function(resolve, reject) { | |
google.script.run | |
.withSuccessHandler(function(blobB64) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Handles client-side conversion of document | |
* data from server to a format we can use for encryption. | |
* Called in both download & email workflows. | |
* | |
* @return {arrayBuffer} Array Buffer of the document content. | |
*/ | |
async function convertPDFData() { | |
// Gets document content; converts | |
// document content back into a usable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function afterAuth(email) { | |
// Run all client code from here. | |
// This will only be called when the user is successfully authenticated. | |
const client = new Virtru.Client({email}); | |
const yourString = prompt('Type a sting to encrypt: ', 'Hello, world!'); | |
const encryptParams = new Virtru.EncryptParamsBuilder() | |
.withArrayBufferSource(arrayBuffer) // Change input to accept arrayBuffer | |
.withDisplayFilename('hello.pdf') // Change display filename to reflect PDF | |
.build(); | |
const ct = await client.encrypt(encryptParams); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Builds policy according to user inputs. | |
* | |
* @param {Array} authUsers The list of authorized users for this piece of content. | |
* @return {Policy} The policy for this piece of content. | |
*/ | |
function buildPolicy() { | |
var policy = new Virtru.PolicyBuilder(); | |
if ($('#watermark-toggle').is(":checked")) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const encryptParams = new Virtru.EncryptParamsBuilder() | |
.withArrayBufferSource(arrayBuffer) | |
.withDisplayFilename(`${docTitle}.pdf`) | |
.withPolicy(policy) | |
.withUsersWithAccess(authorizedUsers) | |
.build(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const client = new Virtru.Client({email}); | |
const encryptParams = new Virtru.EncryptParamsBuilder() | |
.withArrayBufferSource(arrayBuffer) | |
.withDisplayFilename(`${docTitle}.pdf`) | |
.withPolicy(policy) | |
.withUsersWithAccess(authorizedUsers) | |
.build(); | |
const ct = await client.encrypt(encryptParams); | |
var ctString = await ct.toString(); // Encrypt to string rather than to file | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sendEmail(cipherText, recipients, userMessage) { | |
// Get email address of file owner and assign attachment title. | |
var fileOwner = Session.getActiveUser().getEmail(); | |
var fileName = DocumentApp.getActiveDocument().getName() + ".pdf.tdf3.html"; | |
// Provide a basic email body for recipients who do not support HTML. | |
var emailBody = fileOwner + " has shared the encrypted file " + fileName + | |
" with you.\r\n\r\nIt\'s attached below; please download to open in" + | |
" Virtru\'s Secure Reader."; |
OlderNewer