任何人都可以帮助将该代码从 java 转换为 php 吗?在下面阅读更多..
所以..我得到了这段代码..我正在尝试转换为php(5.{3,4,5}..没关系..我只是不想运行tomcat之类的东西)
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);
}
}
当我阅读它时,它从 x509 获取 public_key 并根据 x509 规范使用 public_key 解码它获得的字符串
我一直在尝试这样的 php 没有运气...
$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);
哪个喊
PHP 警告:openssl_public_decrypt(): key parameter is not a valid public key
还尝试使用 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);
哪个喊
openssl_public_decrypt():此 PHP 版本不支持密钥类型!
像这样:
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);
什么都没有喊……还有:
$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():提供的参数不能被强制转换为 X509 证书!
我没主意了...
任何人都可以帮助将该代码从 java 转换为 php 吗?
任何想法.. 非常感谢。如果这已经得到回答,请不要拍摄(我做了谷歌并找到了信息,但没有运气尝试申请。提前致谢。