Howdy, Stranger!

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


DES string crypt on PHP.

vicvondoomvicvondoom Member Posts: 4
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.