File: encryptpw_sha1

package info (click to toggle)
nufw 2.4.3-2.2
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 5,728 kB
  • sloc: ansic: 32,174; sh: 10,146; python: 4,176; makefile: 965; perl: 630; lex: 176; php: 168; yacc: 117; xml: 34
file content (48 lines) | stat: -rw-r--r-- 993 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/perl -w

# Author: Pierre Chifflier <chifflier@inl.fr>
# license: GPLv2
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 2 of the License.


# NIST SHA-1 message digest algorithm

use Digest::SHA1 qw(sha1_base64);

use POSIX;

sub echo_off {
        my($echo) = (&POSIX::ECHO|&POSIX::ECHOK);
        $no_echo = $term_orig;
        $no_echo &= ~$echo;
        $t->setlflag( $no_echo );
        $t->setattr( 0, &TCSANOW);
}

sub echo_on {
        $t->setlflag( $term_orig );
        $t->setattr( 0, &TCSANOW);
}

#
# Set up terminal
$t = POSIX::Termios->new();
$t->getattr();
$term_orig = $t->getlflag();

my $plaintext=shift;

if (!$plaintext) {
  print "password : ";
  echo_off();
  chop ($plaintext=<STDIN>);
  echo_on();
  print "\n";
}

# we append a = because the sha1_base64 function does not append it

print sha1_base64($plaintext), "=\n";