当前位置: 动力学知识库 > 问答 > 编程问答 >

What is the encryption used in this java code? Any PHP equavent for this

问题描述:

I have a java code

import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;

import java.io.PrintStream;

import javax.crypto.Cipher;

import javax.crypto.spec.SecretKeySpec;

public class SecureCardData

{

public static final String retailerid = "61220121";

public String encryptData(String sData)

throws Exception

{

byte[] bPrivateKey = "61220121".getBytes();

SecretKeySpec spec = new SecretKeySpec(bPrivateKey, "DES");

Cipher cipher = Cipher.getInstance("DES");

cipher.init(1, spec);

byte[] bEncryptedData = cipher.doFinal(sData.getBytes());

return Base64.encode(bEncryptedData);

}

public String decryptData(String sData)

throws Exception

{

byte[] bPrivateKey = "61220121".getBytes();

SecretKeySpec spec = new SecretKeySpec(bPrivateKey, "DES");

Cipher cipher = Cipher.getInstance("DES");

cipher.init(2, spec);

byte[] bencryptedData = Base64.decode(sData);

byte[] bDecryptedData = cipher.doFinal(bencryptedData);

return new String(bDecryptedData);

}

public static void main(String[] args)

throws Exception

{

String s = "1800585544448888|445|0611";

SecureCardData sd = new SecureCardData();

String ss = sd.encryptData(s);

System.out.println(ss);

ss = sd.decryptData(ss);

System.out.println(ss);

}

}

Im not into java,can anyone help me make the code equivalent for this in php?

I haven't touched java ever.Finding it really hard to figure out.Is there someone who could help me with this code.?

网友答案:

new SecretKeySpec(bPrivateKey, "DES");

This creates a secret key using the DES specification.

http://en.wikipedia.org/wiki/Data_Encryption_Standard

Note that DES is considered obsolete/easy to break so has not been recommended for use in quite some time.

分享给朋友:
您可能感兴趣的文章:
随机阅读: