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
1c0b3dcd
Commit
1c0b3dcd
authored
Sep 19, 2022
by
Abdullah Danish
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
AFP-001: implements azure vault
parent
b7ba21fe
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
95 additions
and
35 deletions
+95
-35
pom.xml
pom.xml
+12
-0
BlobTriggerFunction.java
.../java/com/nisum/demo/blobStorage/BlobTriggerFunction.java
+12
-35
PGPService.java
src/main/java/com/nisum/demo/blobStorage/pgp/PGPService.java
+71
-0
No files found.
pom.xml
View file @
1c0b3dcd
...
...
@@ -28,6 +28,18 @@
<artifactId>
azure-storage
</artifactId>
<version>
8.6.4
</version>
</dependency>
<dependency>
<groupId>
com.azure
</groupId>
<artifactId>
azure-security-keyvault-secrets
</artifactId>
<version>
4.2.3
</version>
</dependency>
<dependency>
<groupId>
com.azure
</groupId>
<artifactId>
azure-identity
</artifactId>
<version>
1.2.0
</version>
</dependency>
<dependency>
<groupId>
org.bouncycastle
</groupId>
<artifactId>
bcpg-jdk16
</artifactId>
...
...
src/main/java/com/nisum/demo/blobStorage/BlobTriggerFunction.java
View file @
1c0b3dcd
...
...
@@ -2,6 +2,7 @@ package com.nisum.demo.blobStorage;
import
com.microsoft.azure.functions.annotation.*
;
import
com.microsoft.azure.functions.*
;
import
com.nisum.demo.blobStorage.pgp.PGPService
;
import
com.nisum.demo.blobStorage.pgp.PGPUtils
;
import
java.io.IOException
;
...
...
@@ -21,11 +22,13 @@ public class BlobTriggerFunction {
*/
@FunctionName
(
"BlobTriggerFunc"
)
public
void
run
(
@BlobTrigger
(
name
=
"file"
,
path
=
"test/{name}"
,
dataType
=
"binary"
,
connection
=
"AzureWebJobsStorage"
)
byte
[]
content
,
@BlobTrigger
(
name
=
"file"
,
path
=
"test/{name}"
,
dataType
=
"binary"
,
connection
=
"AzureWebJobsStorage"
)
byte
[]
content
,
@BindingName
(
"name"
)
String
name
,
final
ExecutionContext
context
)
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
))
{
String
directoryPath
=
resourceBundle
.
getString
(
"files.directory.path"
)
+
name
;
if
(!
Files
.
exists
(
Paths
.
get
(
directoryPath
)))
{
...
...
@@ -36,38 +39,12 @@ public class BlobTriggerFunction {
fileOutputStream
.
write
(
content
);
}
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'
};
PGPService
pgpService
=
new
PGPService
();
pgpService
.
encryptFile
(
name
);
// Writes data to the output stream
OutputStream
outbound
=
new
FileOutputStream
(
resourceBundle
.
getString
(
"encrypted.files.directory.path"
)
+
name
.
replaceFirst
(
".csv"
,
".asc"
));
String
inbound
=
resourceBundle
.
getString
(
"files.directory.path"
)
+
name
;
try
{
// 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---"
);
// 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);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
context
.
getLogger
()
.
info
(
"Java Blob trigger function processed a blob. Name: "
+
name
+
"\n Size: "
+
content
.
length
+
" Bytes"
);
}
// Closes the output stream
}
context
.
getLogger
().
info
(
"Java Blob trigger function processed a blob. Name: "
+
name
+
"\n Size: "
+
content
.
length
+
" Bytes"
);
}
}
src/main/java/com/nisum/demo/blobStorage/pgp/PGPService.java
View file @
1c0b3dcd
package
com
.
nisum
.
demo
.
blobStorage
.
pgp
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.util.PropertyResourceBundle
;
import
java.util.ResourceBundle
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
public
class
PGPService
{
Logger
logger
=
LoggerFactory
.
getLogger
(
PGPService
.
class
);
public
void
encryptFile
(
String
name
)
throws
IOException
{
ResourceBundle
resourceBundle
=
new
PropertyResourceBundle
(
new
FileInputStream
(
"/Users/eali/Projects/azure/myazurefunctionsdemo/src/main/resources/application.properties"
));
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
OutputStream
outbound
=
new
FileOutputStream
(
resourceBundle
.
getString
(
"encrypted.files.directory.path"
)
+
name
.
replaceFirst
(
".csv"
,
".asc"
));
String
inbound
=
resourceBundle
.
getString
(
"files.directory.path"
)
+
name
;
try
{
// 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
);
logger
.
info
(
"---File Encrypted---"
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
public
void
decryptFile
(
String
name
)
throws
IOException
{
ResourceBundle
resourceBundle
=
new
PropertyResourceBundle
(
new
FileInputStream
(
"/Users/eali/Projects/azure/myazurefunctionsdemo/src/main/resources/application.properties"
));
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
OutputStream
outbound
=
new
FileOutputStream
(
resourceBundle
.
getString
(
"encrypted.files.directory.path"
)
+
name
.
replaceFirst
(
".csv"
,
".asc"
));
String
inbound
=
resourceBundle
.
getString
(
"files.directory.path"
)
+
name
;
try
{
// 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 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
);
logger
.
info
(
"---File Decrypted---"
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
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