php的crypt,PHP crypt() 函数_程序员人生

实例 1

在本实例中,我们将测试不同的算法:

// 2 character salt

if (CRYPT_STD_DES == 1)

{

echo "Standard DES: ".crypt('something','st')."n
";

}

else

{

echo "Standard DES not supported.n
";

}

// 4 character salt

if (CRYPT_EXT_DES == 1)

{

echo "Extended DES: ".crypt('something','_S4..some')."n
";

}

else

{

echo "Extended DES not supported.n
";

}

// 12 character salt starting with $1$

if (CRYPT_MD5 == 1)

{

echo "MD5: ".crypt('something','$1$somethin$')."n
";

}

else

{

echo "MD5 not supported.n
";

}

// Salt starting with $2a$. The two digit cost parameter: 09. 22 characters

if (CRYPT_BLOWFISH == 1)

{

echo "Blowfish: ".crypt('something','$2a$09$anexamplestringforsalt$')."n
";

}

else

{

echo "Blowfish DES not supported.n
";

}

// 16 character salt starting with $5$. The default number of rounds is 5000.

if (CRYPT_SHA256 == 1)

{

echo "SHA-256: ".crypt('something','$5$rounds=5000$anexamplestringforsalt$')."n
"; }

else

{

echo "SHA-256 not supported.n
";

}

// 16 character salt starting with $5$. The default number of rounds is 5000.

if (CRYPT_SHA512 == 1)

{

echo "SHA-512: ".crypt('something','$6$rounds=5000$anexamplestringforsalt$');

}

else

{

echo "SHA-512 not supported.";

}

?>

上面的代码输出如下(取决于操作系统):

Standard DES: stqAdD7zlbByI

Extended DES: _S4..someQXidlBpTUu6

MD5: $1$somethin$4NZKrUlY6r7K7.rdEOZ0w.

Blowfish: $2a$09$anexamplestringforsaleLouKejcjRlExmf1671qw3Khl49R3dfu

SHA-256: $5$rounds=5000$anexamplestringf$KIrctqsxo2wrPg5Ag/hs4jTi4PmoNKQUGWFXlVy9vu9

SHA-512: $6$rounds=5000$anexamplestringf$Oo0skOAdUFXkQxJpwzO05wgRHG0dhuaPBaOU/

oNbGpCEKlf/7oVM5wn6AN0w2vwUgA0O24oLzGQpp1XKI6LLQ0.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值