c# - C# 和 PHP 中的 Ruby string#crypt

标签 c# php ruby string crypt

我有一个 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(3)

    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

  • crypt

    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

    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

  • crypt.crypt

    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

    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.

  • A C# implementation of Unix crypt()

关于c# - C# 和 PHP 中的 Ruby string#crypt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1898659/

相关文章:

php - 跨域xmlhttp

ruby - 如何在 Ruby 中更新 XML 文件?

Ruby 如何合并两个标题略有不同的 CSV 文件

ruby - Emacs:导航至编译错误

c# - 当对象包含列表时覆盖相等成员

PHP 将变量传递到下一页

PHP Mysql 跨数据库连接

c# - 为什么在内部类中使用公共(public)方法?

c# - 使用 WHERE 子句获取可为空列的 SUM

c# - 使用 C# 在 Excel 中复制/粘贴单元格