-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSecretsHelper.codeunit.al
56 lines (51 loc) · 1.61 KB
/
SecretsHelper.codeunit.al
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
codeunit 70001 "Secret Helper"
{
Access = Internal;
[NonDebuggable]
procedure SaveSecret(KeyName: Text; SecretValue: Text)
var
EncryptionErr: Label 'The secret cannot be stored. The encryption is not enabled.';
EncrytedBuffer: Text;
begin
if not EncryptionEnabled() then begin
Error(EncryptionErr);
end;
EncrytedBuffer := Encrypt(SecretValue);
IsolatedStorage.Set(KeyName, EncrytedBuffer, DataScope::Module);
end;
[NonDebuggable]
procedure GetSecret(KeyName: Text): Text
var
SecretValue: Text;
PlainBuffer: Text;
begin
if not EncryptionEnabled() then
exit('');
if not IsolatedStorage.Contains(KeyName, DataScope::Module) then
exit('');
if not IsolatedStorage.Get(KeyName, DataScope::Module, SecretValue) then
exit('');
PlainBuffer := Decrypt(SecretValue);
exit(PlainBuffer);
end;
[NonDebuggable]
procedure DeleteSecret(KeyName: Text)
begin
IsolatedStorage.Delete(KeyName, DataScope::Module);
end;
[NonDebuggable]
procedure UpdateSecret()
var
SecretDemoSetup: Record "Secret Demo Setup";
SecretInput: Page "Secret Input";
SecretValue: Text;
begin
SecretDemoSetup.Get();
SecretDemoSetup.Testfield("Function URL");
SecretDemoSetup.TestField("Access Key Code");
if SecretInput.RunModal() = Action::OK then begin
SecretValue := SecretInput.GetSecret();
SaveSecret(SecretDemoSetup."Access Key Code", SecretValue);
end;
end;
}