我有一个 ruby 客户端程序,它像这样用 string#crypt 加密密码
encrypted = password.crypt(SALT)
# removing first two characters which actually are the salt for safety
return encrypted[2, encrypted.size - 2]
然后它将它发送到服务器以与它存储的预加密字符串进行比较。 我如何需要能够从 c# 应用程序和 php 网页发送相同的加密密码,并且仍然能够使用来自任何其他客户端的相同密码登录。
C# 和 php 中用于加密的等效代码是什么?
最佳答案
C
-
crypt() is the password encryption function. It is based on the Data Encryption Standard algorithm with variations intended (among other things) to discourage use of hardware implementations of a key search.
key is a user's typed password.
salt is a two-character string chosen from the set [a-zA-Z0-9./]. This string is used to perturb the algorithm in one of 4096 different ways.
ruby
-
Applies a one-way cryptographic hash to str by invoking the standard library function crypt. The argument is the salt string, which should be two characters long, each character drawn from [a-zA-Z0-9./].
PHP
-
crypt() will return an encrypted string using the standard Unix DES-based encryption algorithm or alternative algorithms that may be available on the system.
python
-
This module implements an interface to the crypt(3) routine, which is a one-way hash function based upon a modified DES algorithm;
C#
.NET Framework 不包含用于 Unix crypt 函数的 API,但这里有一些提供实现的库:
-
CryptAPI is a C# library that contains unimplemented algorithms in the .NET framework (NT, NTLM, BlowFish, DES and MD5) linking and emulating the crypt() unix function re-programmed in C#. The main purpose is to provide backward compatiblity.
关于c# - C# 和 PHP 中的 Ruby string#crypt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1898659/