Anyone can help convert that code from java to php ? Read more below..
So .. I got this piece of code .. I'm trying to convert to php ( 5.{3,4,5} .. doesn't matter .. I just don't want to run tomcat and stuff )
private static byte[] cAGLT(String lC){
try {
PublicKey PUBLIC_KEY;
String key = "MIIBuDCCASwGByqGSM44BAEwggEfAoGBAP1/U4EddRIpUt9KnC7s5Of2EbdSPO9E.............long 593 char stuff here";
KeyFactory keyFactory = KeyFactory.getInstance("DSA");
PUBLIC_KEY = keyFactory.generatePublic(new X509EncodedKeySpec(Base64.decodeBase64(key.getBytes())));
byte[] decodedBytes = Base64.decodeBase64(lC.getBytes());
ByteArrayInputStream in = new ByteArrayInputStream(decodedBytes);
DataInputStream dIn = new DataInputStream(in);
int textLength = dIn.readInt();
byte[] lT = new byte[textLength];
dIn.read(lT);
byte[] hash = new byte[dIn.available()];
dIn.read(hash);
try{
Signature signature = Signature.getInstance("SHA1withDSA");
signature.initVerify(PUBLIC_KEY);
signature.update(lT);
try{
signature.verify(hash);
} catch (Exception e) {
throw e;
}
}catch (Exception e){
throw e;
}
return lT;
}catch (Exception e){
throw new Error(e);
}
}
As I read it, it gets the public_key from the x509 and decodes the string it gets using a public_key as per x509 spec
I've been trying like this in php with no luck ...
$key = "MIIBuDCCASwGByqGSM44BAEwggEfAoGBAP1/U4EddRIpUt9KnC7s5Of2EbdSPO9E.............long 593 char stuff here";
$key = "-----BEGIN PUBLIC KEY-----\n" . wordwrap($key, 64, "\n", true) . "-----END PUBLIC KEY-----"; // no \n before the ----END because it already has one
$key = openssl_pkey_get_public($key);
$key = openssl_pkey_get_details($key);
$key = "-----BEGIN PUBLIC KEY-----\n" . wordwrap(base64_encode($key['dsa']['pub_key']), 64, "\n", true)."\n-----END PUBLIC KEY-----";
$data = null;
openssl_public_decrypt($todecode, $data, $key);
which yells
PHP Warning: openssl_public_decrypt(): key parameter is not a valid public key
Also tried like this with phpseclib ( http://phpseclib.sourceforge.net/pear.htm )
$key = "MIIBuDCCASwGByqGSM44BAEwggEfAoGBAP1/U4EddRIpUt9KnC7s5Of2EbdSPO9E.............long 593 char stuff here";
$key = "-----BEGIN PUBLIC KEY-----\n" . wordwrap($key, 64, "\n", true) . "-----END PUBLIC KEY-----";
$data = null;
openssl_public_decrypt($licenseContent, $data, $key);
Which yells
openssl_public_decrypt(): key type not supported in this PHP build!
And like this:
include('BigInteger.php');
include('ASN1.php');
include('X509.php');
$key = "MIIBuDCCASwGByqGSM44BAEwggEfAoGBAP1/U4EddRIpUt9KnC7s5Of2EbdSPO9E.............long 593 char stuff here";
$key = "-----BEGIN CERTIFICATE-----\n" . wordwrap($key, 64, "\n", true) . "-----END CERTIFICATE-----";
$x509 = new File_X509();
$cert = $x509->loadX509($key);
print_r($cert);
Which yells NOTHING... also:
$key = "MIIBuDCCASwGByqGSM44BAEwggEfAoGBAP1/U4EddRIpUt9KnC7s5Of2EbdSPO9E.............long 593 char stuff here";
$key = "-----BEGIN CERTIFICATE-----\n" . wordwrap($key, 64, "\n", true) . "-----END CERTIFICATE-----";
echo openssl_x509_read($key);
openssl_x509_read(): supplied parameter cannot be coerced into an X509 certificate!
I'm out of ideas...
Anyone can help convert that code from java to php ?
Any ideas .. greatly appreciated. Please don't shoot if this has already been answered ( I did google and found info but no luck trying to apply. Thanks in advance.