在客户端和服务器之间生成相同的JOSE令牌(PHP-C#)
我试图用这两个库生成相同的密钥:在客户端和服务器之间生成相同的JOSE令牌(PHP-C#),c#,php,encryption,jwt,jose,C#,Php,Encryption,Jwt,Jose,我试图用这两个库生成相同的密钥: 这是给C的# 这是针对PHP的 我已实施了两项措施: 在C#中: 它们是相似的代码不是吗 但结果不同: 2.JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ
- 这是给C的#
- 这是针对PHP的
include(__DIR__ . "/../libs/jose/autoload.php");
$file = __DIR__ . '/../keys/private.key';
$contents = file_get_contents($file);
// This is the input we want to load verify.
$input = @$_GET["input"];
$jwk = new \Jose\KeyConverter\RSAKey($contents);
// We create our loader.
$loader = new Jose\Loader();
$loader->load($input);
// The payload is decrypted using our key.
$jws = $loader->loadAndDecryptUsingKey(
$input, // The input to load and decrypt
new \Jose\Object\JWK($jwk->toArray()), // The symmetric or private key
['RSA-OAEP'], // A list of allowed key encryption algorithms
['A256GCM'], // A list of allowed content encryption algorithms
$recipient_index // If decrypted, this variable will be set with the recipient index used to decrypt
);
$coreData["content"] = $jws->getPayload();
出现以下异常:
致命错误:未捕获的InvalidArgumentException:无法解密
JWE。在C:\xampp\htdocs\z3nth10n PHP\libs\jose\Decrypter.PHP:80堆栈中
跟踪:#0 C:\xampp\htdocs\z3nth10n PHP\libs\jose\Loader.PHP(95):
Jose\Decrypter->decryptUsingKeySet(对象(Jose\Object\JWE),
对象(Jose\Object\JWKSet),NULL)#1
C:\xampp\htdocs\z3nth10n PHP\libs\jose\Loader.PHP(30):
Jose\Loader->loadAndDecrypt('eyJhbGciOiJSU0E…',
对象(Jose\Object\JWKSet),数组,数组,NULL)#2
C:\xampp\htdocs\z3nth10n PHP\includes\actions.PHP(321):
Jose\Loader->loadAndDecryptUsingKey('eyjhbgcoiijsu0e…'),
对象(Jose\Object\JWK),数组,数组,NULL)#3
C:\xampp\htdocs\z3nth10n PHP\api.PHP(9):
包括('C:\xampp\htdocs…')#4{main}抛出
第80行的C:\xampp\htdocs\z3nth10n PHP\libs\jose\Decrypter.PHP
我已经在代码中查找了很多时间,我意识到问题不在代码中,问题在生成的令牌中。我不知道我能做什么,你可以在这里测试
。。。然后
有什么建议吗?来自JOSE(php)的示例展示了创建密钥的不同方法。可能是这个问题:我已经检查了这个例子,第一个方法只加载密钥,第二个方法完成工作,这只生成了一个不同的输出,可以用PHP解密。但当我尝试用PHP反编译C#令牌时,问题就出现了。
private static RSACryptoServiceProvider GetPubKey()
{
ConnPreCheck();
JObject obj = JsonConvert.DeserializeObject<JObject>(getPubKey.HttpGet());
pubkeyStr = obj["data"]["pubKey"].ToString();
return PemKeyUtils.GetRSAProviderFromPemString(pubkeyStr);
}
include(__DIR__ . "/../libs/jose/autoload.php");
$file = __DIR__ . '/../keys/public.key';
$contents = file_get_contents($file);
// This is the input we want to load verify.
$input = @$_GET["input"];
$key = new \Jose\KeyConverter\RSAKey($contents);
$jwe = \Jose\Factory\JWEFactory::createJWEToCompactJSON(
$input, // The message to encrypt
new \Jose\Object\JWK($key->toArray()), // The key of the recipient
[
'alg' => 'RSA-OAEP',
'enc' => 'A256GCM',
'zip' => 'DEF',
]
);
include(__DIR__ . "/../libs/jose/autoload.php");
$file = __DIR__ . '/../keys/private.key';
$contents = file_get_contents($file);
// This is the input we want to load verify.
$input = @$_GET["input"];
$jwk = new \Jose\KeyConverter\RSAKey($contents);
// We create our loader.
$loader = new Jose\Loader();
$loader->load($input);
// The payload is decrypted using our key.
$jws = $loader->loadAndDecryptUsingKey(
$input, // The input to load and decrypt
new \Jose\Object\JWK($jwk->toArray()), // The symmetric or private key
['RSA-OAEP'], // A list of allowed key encryption algorithms
['A256GCM'], // A list of allowed content encryption algorithms
$recipient_index // If decrypted, this variable will be set with the recipient index used to decrypt
);
$coreData["content"] = $jws->getPayload();