使用Openssl解密JWE的内容加密密钥

时间:2019-04-16 03:44:48

标签: openssl cryptography elliptic-curve jwe

我有一个JWE,我想用openssl(和其他命令行)解密内容加密密钥(cek)

这是我的JWE:

eyJlcGsiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiJHQ2wtLWxRSGI3TktZVTNqWHBLVklfQllhVGxBTFQ1SkZQZGwzc2JCOW1ZIiwieSI6IkFEUlgyNVBCU2xaSkU3OWRyRVQwQVJ0UnFaQWtVSU1OdDlhYTJiYmpCWVkifSwiZW5jIjoiQTEyOEdDTSIsImFsZyI6IkVDREgtRVMrQTEyOEtXIn0.IFiUOn11TxTgnYWCA2rJLTYV3_r2n_qW.[IV].[Payload].[Sign]

因此,现在我已检索到以下元素:

临时公共密钥(EPK):

-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEGCl++lQHb7NKYU3jXpKVI/BYaTlA
LT5JFPdl3sbB9mYANFfbk8FKVkkTv12sRPQBG1GpkCRQgw231prZtuMFhg==
-----END PUBLIC KEY-----

私钥:

-----BEGIN EC PRIVATE KEY-----
MEECAQAwEwYHKoZIzj0CAQYIKoZIzj0DAQcEJzAlAgEBBCC0pi7An729X2hjD01f
TwwrlDzFIZ1XaNpJjqM01hyVuA==
-----END EC PRIVATE KEY-----

私钥和EPK中的共享密钥(基于64):

5gMHliQ850OswmbhgSK/QR6QU43sTGfXxbQDPhgK0Qw=

以64为基的密钥加密密钥(kek):

jy5VPMvuVJTxTwtf1rhUKA==

解密的JWE标头:

{
  "epk": {
    "kty": "EC",
    "crv": "P-256",
    "x": "GCl--lQHb7NKYU3jXpKVI_BYaTlALT5JFPdl3sbB9mY", 
    "y": "ADRX25PBSlZJE79drET0ARtRqZAkUIMNt9aa2bbjBYY"
  },
  "enc": "A128GCM",
  "alg": "ECDH-ES+A128KW"
}

现在,我尝试解密CEK:IFiUOn11TxTgnYWCA2rJLTYV3_r2n_qW。但是我有一些错误。

此处命令:

openssl enc -nosalt -aes128-wrap -base64 -k $(base64 kek) -d -in encrypted-cek.64 -out cek

base64 kek等于jy5VPMvuVJTxTwtf1rhUKA==

并且加密的cek.64包含IFiUOn11TxTgnYWCA2rJLTYV3/r2n/qW(我已将cek从base64url转换为base64)

出现错误:

Error setting cipher id-aes128-wrap
140295367438784:error:0607B0AA:digital envelope routines:EVP_CipherInit_ex:wrap mode not allowed:../crypto/evp/evp_enc.c:160:

我忘记了什么。

0 个答案:

没有答案