Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
eduGAIN Access Check - Account manager
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
edugain
eduGAIN Access Check - Account manager
Commits
5c98e1c3
Commit
5c98e1c3
authored
7 years ago
by
Guillaume ROUSSE
Browse files
Options
Downloads
Patches
Plain Diff
add OTP-based encryption/decryption functions
parent
93a067af
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/AccountManager/Tools.pm
+31
-0
31 additions, 0 deletions
lib/AccountManager/Tools.pm
t/tools.t
+23
-0
23 additions, 0 deletions
t/tools.t
with
54 additions
and
0 deletions
lib/AccountManager/Tools.pm
+
31
−
0
View file @
5c98e1c3
...
...
@@ -7,8 +7,39 @@ use Digest::SHA;
use
Digest::
MD5
;
use
Encode
;
use
English
qw(-no_match_vars)
;
use
List::
MoreUtils
qw(pairwise)
;
use
MIME::
Base64
;
use
Template
;
sub
encrypt
{
my
(
$string
,
$key
)
=
@_
;
my
@string_chars
=
split
(
//
,
$string
);
my
@key_chars
=
split
(
//
,
$key
);
return
encode_base64
(
otp
(
\
@string_chars
,
\
@key_chars
));
}
sub
decrypt
{
my
(
$string
,
$key
)
=
@_
;
my
@string_chars
=
split
(
//
,
decode_base64
(
$string
));
my
@key_chars
=
split
(
//
,
$key
);
return
otp
(
\
@string_chars
,
\
@key_chars
);
}
sub
otp
{
my
(
$string
,
$key
)
=
@_
;
my
@chars
=
pairwise
{
chr
(
ord
(
$a
)
^
ord
(
$b
))
}
@$string
,
@$key
;
return
join
('',
@chars
);
}
# get SHA256 hash for a string
sub
sha256_hash
{
my
(
$s
)
=
@_
;
...
...
This diff is collapsed.
Click to expand it.
t/tools.t
0 → 100644
+
23
−
0
View file @
5c98e1c3
#!/usr/bin/perl
use
strict
;
use
warnings
;
use
English
qw(-no_match_vars)
;
use
Test::
More
;
use
AccountManager::
Tools
;
plan
tests
=>
4
;
my
$key
=
AccountManager::Tools::
generate_token
(
undef
,
10
);
my
$secret
=
AccountManager::Tools::
generate_password
();
ok
(
$key
ne
$secret
,
'
key and secret are random strings
');
ok
(
length
(
$key
)
==
length
(
$secret
),
'
key and secret have same size
');
my
$encrypted_secret
=
AccountManager::Tools::
encrypt
(
$secret
,
$key
);
ok
(
$encrypted_secret
ne
$secret
,
'
crypted_secret and secret are differents
');
my
$decrypted_secret
=
AccountManager::Tools::
decrypt
(
$encrypted_secret
,
$key
);
ok
(
$decrypted_secret
eq
$secret
,
'
decrypted_secret and secret are equals
');
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment