Ruby string#crypt in c# and php
I have a ruby client program that encrypts a password with string#crypt like so
encrypted = password.crypt(SALT)
# removing first two characters which actually are the salt for safety
return encrypted[2, encrypted.size - 2]
it then sends it to a server for comparison with it's stored pre-开发者_如何转开发encrypted string. how ever I need to be able to send the same encrypted password form a c# app and a php web page and still be able to log in with the same password from any of the other clients.
what would be the equivalent code in C# and php for the encryption?
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#
The .NET Framework doesn't include an API for the Unix crypt function, but here are some libraryies that provide implementations:
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()
精彩评论