Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

Encrypt/Decrypt & Upload a File to S3 #42

Open
jelordreygulle opened this issue Aug 13, 2020 · 2 comments
Open

Encrypt/Decrypt & Upload a File to S3 #42

jelordreygulle opened this issue Aug 13, 2020 · 2 comments

Comments

@jelordreygulle
Copy link

Do you have some example implementation Sir on Encrypt/Decrypt & Upload a File to S3 using the node js sdk of virtru ? Thanks.

@biscoe916
Copy link
Contributor

Hi @jelordreygulle below is an example from our dev hub. Take a look and let me know if this helps.

const Virtru = require('virtru-sdk');
const AWS = require('aws-sdk');

/**
 * Example showing how to encrypt and write a file to S3.
 * 
 * This example assumes you've installed the aws-sdk module and set up your AWS
 * credentials file. For more information, see: https://github.com/aws-samples/aws-nodejs-sample
 *
 * Example usage: 
 *   node sample.js [email protected] $(cat ~/.virtru/appId) hello.txt my-s3-bucket
 *
 * If your bucket is configured for static website hosting you'll be able to 
 * open up Secure Reader directly from the object link.
 * (e.g., http://my-s3-bucket.s3-website-us-west-2.amazonaws.com/hello.txt.html)
 */
const email = process.argv[2];
const appId = process.argv[3];
const localFilename = process.argv[4];
const bucketName = process.argv[5];

// Initialize the Virtru and S3 clients.
const client = new Virtru.Client({email, appId});
const s3 = new AWS.S3();
// Derive the object key to use by appending .html for easy browser support.
const key = `${localFilename}.html`;
const encryptParams = new Virtru.EncryptParamsBuilder()
    .withFileSource(localFilename)
    .withDisplayFilename(localFilename)
    .build();
// The returned stream can be passed directly to s3.upload().
client.encrypt(encryptParams).then(ct =>
 s3.upload({Body: ct, Bucket: bucketName, Key: key, ContentType: 'html/text'}, onComplete));

function onComplete(err, data) {
  console.log(`${localFilename} encrypted and uploaded to S3 as ${key}`);
}

@jelordreygulle
Copy link
Author

Thank you for this one Sir .

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants