原创作品,允许转载,转载时请务必以超链接形式标明文章
原始出处
、作者信息和本声明。否则将追究法律责任。
http://dgd2010.blog.51cto.com/1539422/1712244
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
|
static
const
struct
crypt_method methods[] = {
/* method
prefix minlen, maxlen rounds description */
{
"des"
,
""
,
2, 2, 0,
N_(
"standard 56 bit DES-based crypt(3)"
) },
{
"md5"
,
"$1$"
, 8, 8, 0,
"MD5"
},
#if defined OpenBSD
|| defined FreeBSD || (defined __SVR4 && defined __sun)
{
"bf"
,
"$2a$"
, 22, 22, 1,
"Blowfish"
},
#endif
#if
defined HAVE_LINUX_CRYPT_GENSALT
{
"bf"
,
"$2a$"
, 22,
22, 1,
"Blowfish, system-specific on 8-bit chars"
},
/* algorithm 2y
fixes CVE-2011-2483 */
{
"bfy"
,
"$2y$"
, 22, 22, 1,
"Blowfish, correct handling of 8-bit chars"
},
#endif
#if defined
FreeBSD
{
"nt"
,
"$3$"
, 0, 0, 0,
"NT-Hash"
},
#endif
#if defined HAVE_SHA_CRYPT
/* http://people.redhat.com/drepper/SHA-crypt.txt */
{
"sha-256"
,
"$5$"
, 8, 16, 1,
"SHA-256"
},
{
"sha-512"
,
"$6$"
, 8, 16, 1,
"SHA-512"
},
#endif
/* http://www.crypticide.com/dropsafe/article/1389 */
/*
* Actually the maximum salt length is arbitrary, but
Solaris by default
* always uses 8 characters:
* http://cvs.opensolaris.org/source/xref/onnv/onnv-gate/ \
*
usr/src/lib/crypt_modules/sunmd5/sunmd5.c#crypt_gensalt_impl
*/
#if
defined __SVR4 && defined __sun
{
"sunmd5"
,
"$md5$"
,
8, 8, 1,
"SunMD5"
},
#endif
{ NULL, NULL,
0, 0, 0, NULL }
};
|
1
|
vim encryptionwithcrypt.c
|
1
2
3
4
5
6
7
8
9
10
11
|
#define _XOPEN_SOURCE
#include <unistd.h>
#include <stdio.h>
int
main(
void
)
{
char
*encryption;
char
key[] =
"yourkey"
;
encryption= crypt(key,
"$6$yoursalt$"
);
printf
(
"encryption is: %s\n"
, encryption);
return
0;
}
|
1
2
|
gcc -lcrypt encryptionwithcrypt.c -o encryptionwithcrypt
.
/encryptionwithcrypt
|
1
2
3
|
# Ubuntu only, available on Ubuntu
which
mkpassed || apt-get
install
-y whois
mkpasswd --salt=
"yoursalt"
--method=sha-512
|