Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
MyAzureFunctionsDemo
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abdullah Danish
MyAzureFunctionsDemo
Commits
29f9b069
Commit
29f9b069
authored
Sep 16, 2022
by
Eibad Ali
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[GAFP-4] : PGP Encryption/Decryption
parent
d33ee051
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
28 deletions
+31
-28
BlobTriggerFunction.java
.../java/com/nisum/demo/blobStorage/BlobTriggerFunction.java
+26
-27
application.properties
src/main/resources/application.properties
+5
-1
No files found.
src/main/java/com/nisum/demo/blobStorage/BlobTriggerFunction.java
View file @
29f9b069
...
...
@@ -31,42 +31,41 @@ public class BlobTriggerFunction {
)
throws
IOException
{
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
))
{
String
directoryPath
=
resourceBundle
.
getString
(
"files.directory.path"
)+
name
;
if
(!
Files
.
exists
(
Paths
.
get
(
directoryPath
)))
{
Files
.
createFile
(
Paths
.
get
(
directoryPath
));
}
String
directoryPath
=
resourceBundle
.
getString
(
"files.directory.path"
)
+
name
;
if
(!
Files
.
exists
(
Paths
.
get
(
directoryPath
)))
{
Files
.
createFile
(
Paths
.
get
(
directoryPath
));
}
try
(
FileOutputStream
fileOutputStream
=
new
FileOutputStream
(
directoryPath
,
true
))
{
try
(
FileOutputStream
fileOutputStream
=
new
FileOutputStream
(
directoryPath
,
true
))
{
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"
);
String
inbound
=
"/Users/eali/Projects/azure/myazurefunctionsdemo/src/main/resources/inbound/eibad.csv"
;
InputStream
inputStreamSecretKey
=
new
FileInputStream
(
resourceBundle
.
getString
(
"gpg.keychain.secret.key"
));
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
InputStream
inputStreamSecretKey
=
new
FileInputStream
(
"/Users/eali/Projects/azure/myazurefunctionsdemo/src/main/resources/keys/gappoc.asc"
);
InputStream
inputStreamPublicKey
=
new
FileInputStream
(
"/Users/eali/Projects/azure/myazurefunctionsdemo/src/main/resources/keys/gappocPublic.asc"
)
;
char
[]
pass
=
{
'n'
,
'i'
,
's'
,
'u'
,
'm'
,
'1'
,
'2'
,
'3'
,
'4'
};
OutputStream
outbound
=
new
FileOutputStream
(
resourceBundle
.
getString
(
"encrypted.files.directory.path"
)
+
name
.
replaceFirst
(
".csv"
,
".asc"
)
);
String
inbound
=
resourceBundle
.
getString
(
"files.directory.path"
)
+
name
;
try
{
// PGPPublicKey key = PGPUtils.readPublicKey(inputStream);
// use it when using only public key
// context.getLogger().info("key : "+ key.isEncryptionKey()+" "+key.getCreationTime() +"::"+key.toString());
// use it when using only public key
// PGPPublicKey key = PGPUtils.readPublicKey(inputStream);
// use it to get secret key when using public + private key
// PGPSecretKey pgpSecretKey = PGPUtils.readSecretKey(inputStream);
// for encryption
PGPUtils
.
encryptAndSignFile
(
outbound
,
inbound
,
inputStreamPublicKey
,
inputStreamSecretKey
,
true
,
true
,
pass
);
context
.
getLogger
().
info
(
"---File Encrypted---"
);
//
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("----"
);
//
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
);
// PGPUtils.encryptAndSignFile(outbound,inbound,inputStreamPublicKey,inputStreamSecretKey,true,true,pass);
// outbound.close();
//
context
.
getLogger
().
info
(
"---encryptAndSignFile---"
);
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
)
{
e
.
printStackTrace
();
}
...
...
src/main/resources/application.properties
View file @
29f9b069
files.directory.path
=
/Users/adanish/Documents/azure-function-blob-storage-examples/src/main/resources/files/
\ No newline at end of file
files.directory.path
=
/Users/eali/Projects/azure/myazurefunctionsdemo/src/main/resources/files/
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment