Commit 29f9b069 authored by Eibad Ali's avatar Eibad Ali

[GAFP-4] : PGP Encryption/Decryption

parent d33ee051
...@@ -31,7 +31,7 @@ public class BlobTriggerFunction { ...@@ -31,7 +31,7 @@ public class BlobTriggerFunction {
) throws IOException { ) throws IOException {
ResourceBundle resourceBundle = new PropertyResourceBundle(new FileInputStream("/Users/eali/Projects/azure/myazurefunctionsdemo/src/main/resources/application.properties")); ResourceBundle resourceBundle = new PropertyResourceBundle(new FileInputStream("/Users/eali/Projects/azure/myazurefunctionsdemo/src/main/resources/application.properties"));
if (Pattern.matches("[a-z|A-Z]*.csv", name)) { if (Pattern.matches("[a-z|A-Z]*.csv", name)) {
String directoryPath = resourceBundle.getString("files.directory.path")+name; String directoryPath = resourceBundle.getString("files.directory.path") + name;
if (!Files.exists(Paths.get(directoryPath))) { if (!Files.exists(Paths.get(directoryPath))) {
Files.createFile(Paths.get(directoryPath)); Files.createFile(Paths.get(directoryPath));
} }
...@@ -39,34 +39,33 @@ public class BlobTriggerFunction { ...@@ -39,34 +39,33 @@ public class BlobTriggerFunction {
try (FileOutputStream fileOutputStream = new FileOutputStream(directoryPath, true)) { try (FileOutputStream fileOutputStream = new FileOutputStream(directoryPath, true)) {
fileOutputStream.write(content); fileOutputStream.write(content);
} }
// String encryptedFilePath = resourceBundle.getString("files.directory.path")+name;
OutputStream outbound = new FileOutputStream("/Users/eali/Projects/azure/myazurefunctionsdemo/src/main/resources/outbound/eibad.csv"); InputStream inputStreamSecretKey = new FileInputStream(resourceBundle.getString("gpg.keychain.secret.key"));
String inbound = "/Users/eali/Projects/azure/myazurefunctionsdemo/src/main/resources/inbound/eibad.csv"; InputStream inputStreamPublicKey = new FileInputStream(resourceBundle.getString("gpg.keychain.public.key"));
char[] pass = {'n', 'i', 's', 'u', 'm', '1', '2', '3', '4'};
// Writes data to the output stream // Writes data to the output stream
InputStream inputStreamSecretKey = new FileInputStream("/Users/eali/Projects/azure/myazurefunctionsdemo/src/main/resources/keys/gappoc.asc"); OutputStream outbound = new FileOutputStream(resourceBundle.getString("encrypted.files.directory.path") + name.replaceFirst(".csv",".asc"));
InputStream inputStreamPublicKey = new FileInputStream("/Users/eali/Projects/azure/myazurefunctionsdemo/src/main/resources/keys/gappocPublic.asc"); String inbound= resourceBundle.getString("files.directory.path") + name;
char[] pass = {'n','i','s','u','m','1','2','3','4'};
try { try {
// PGPPublicKey key = PGPUtils.readPublicKey(inputStream);
// use it when using only public key // use it when using only public key
// context.getLogger().info("key : "+ key.isEncryptionKey()+" "+key.getCreationTime() +"::"+key.toString()); // PGPPublicKey key = PGPUtils.readPublicKey(inputStream);
// use it to get secret key when using public + private key
// PGPSecretKey pgpSecretKey = PGPUtils.readSecretKey(inputStream); // PGPSecretKey pgpSecretKey = PGPUtils.readSecretKey(inputStream);
// use it when using public + private key
// context.getLogger().info("key : "+ pgpSecretKey.isSigningKey()+" "+pgpSecretKey.getKeyID() +"::"+pgpSecretKey.toString());
// context.getLogger().info("----");
// PGPUtils.encryptAndSignFile(outbound,inbound,inputStreamPublicKey,inputStreamSecretKey,true,true,pass); // for encryption
// outbound.close(); PGPUtils.encryptAndSignFile(outbound, inbound, inputStreamPublicKey, inputStreamSecretKey, true, true, pass);
// context.getLogger().info("---File Encrypted---");
context.getLogger().info("---encryptAndSignFile---");
// for decryption
// InputStream fileToBeDecrypt = new FileInputStream(resourceBundle.getString("encrypted.files.directory.path") + name.replaceFirst(".csv", ".asc"));
// OutputStream inboundN = new FileOutputStream(resourceBundle.getString("decrypted.files.directory.path"));
// PGPUtils.decryptFile(fileToBeDecrypt, inboundN, inputStreamSecretKey, pass, inputStreamPublicKey);
InputStream outboundIn = new FileInputStream("/Users/eali/Projects/azure/myazurefunctionsdemo/src/main/resources/outbound/eibad.csv");
OutputStream inboundN = new FileOutputStream("/Users/eali/Projects/azure/myazurefunctionsdemo/src/main/resources/out/a.csv");
PGPUtils.decryptFile(outboundIn,inboundN, inputStreamSecretKey,pass,inputStreamPublicKey);
outboundIn.close();
inboundN.close();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
......
files.directory.path = /Users/adanish/Documents/azure-function-blob-storage-examples/src/main/resources/files/ files.directory.path = /Users/eali/Projects/azure/myazurefunctionsdemo/src/main/resources/files/
\ No newline at end of file encrypted.files.directory.path = /Users/eali/Projects/azure/myazurefunctionsdemo/src/main/resources/encrypted/
decrypted.files.directory.path = /Users/eali/Projects/azure/myazurefunctionsdemo/src/main/resources/decrypted/a.csv
gpg.keychain.public.key = /Users/eali/Projects/azure/myazurefunctionsdemo/src/main/resources/keys/gappocPublic.asc
gpg.keychain.secret.key = /Users/eali/Projects/azure/myazurefunctionsdemo/src/main/resources/keys/gappoc.asc
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment