DES string crypt on PHP. - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

DES string crypt on PHP.

vicvondoomvicvondoom Posts: 4Member
Hi everybody, i'm searching a good library to crypt strings with DES algorythm.
My C# example:

public string EncryptData(string plainText)
DES des = new DESCryptoServiceProvider();
des.Mode = CipherMode.ECB;
des.Padding = PaddingMode.PKCS7;
des.Key = atvyKey;
des.IV = atvyKey;
byte[] bytes = Encoding.UTF8.GetBytes(plainText);
byte[] resultBytes = des.CreateEncryptor().TransformFinalBlock(bytes, 0, bytes.Length);

return Convert.ToBase64String(resultBytes);

the atvyKey it's a private byte[].

Java example:

public String encrypt(String plainText) {
String encryptedString = null;
try {
// initializes the cipher with a key.
cipher.init(Cipher.ENCRYPT_MODE, key);

byte[] plainTextAsASCII = plainText.getBytes(CHARSET);

// decrypts data in a single-part or multi-part operation
byte[] encryptedBytes = cipher.doFinal(plainTextAsASCII);

encryptedString = new sun.misc.BASE64Encoder().encode(encryptedBytes);
} catch (Exception e) {
//throw new DDICryptoException(e);

return encryptedString;

Both two function product a string and i can decrypt the string correctly.
But exist in PHP some libriaries that do this kind of work?

Thank you!
Sign In or Register to comment.