PHP

Moderators: None (Apply to moderate this forum)
Number of threads: 1847
Number of posts: 5013

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
DES string crypt on PHP. Posted by vicvondoom on 8 Jan 2012 at 3:43 AM
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) {
//LOG.error(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!



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.