具有A256GCMKW算法的Ruby JWE和具有A256GCM的加密

时间:2019-09-23 21:30:58

标签: ruby jwe jose

我已经使用alg:“ A256GCMKW”,enc:“ A256GCM”和channelSecurityContext:“ SHARED_SECRET”对JWE中的纯文本进行了加密。我为此使用Jose Gem。我已经生成了可以解密但其他方无法解密的有效负载。他们正在为此使用雨云。有生成的有效载荷,我无法解密。

有人可以帮忙吗?我需要解密以下JWE。

ew0KICAiYWxnIiA6ICJBMjU2R0NNS1ciLA0KICAiaXYiIDogIlRNa2hjbkJZU082V2pueGEiLA0KICAidGFnIiA6ICJtelZqQjZ5aE5FVDEwTVYtYlp6U1lnIiwNCiAgImVuYyIgOiAiQTI1NkdDTSIsDQogICJ0eXAiIDogIkpPU0UiLA0KICAia2lkIiA6ICJGREpNUE8zQllLTldUTFFON1JCNDEzRFRQUzhPNlBuZzBYc2pPU3BobTI1MEFxMWtBIiwNCiAgImNoYW5uZWxTZWN1cml0eUNvbnRleHQiIDogIlNIQVJFRF9TRUNSRVQiLA0KICAiaWF0IiA6ICIxNTY5ODM4OTM2Ig0KfQ.pL9EOdzwq65L3OMIPd3x5YBlZgeXXmPbqlBg2ch7w0E.JTS4C7mnDsUKundm.022Xz4k2xUFgKxVwCHdwalJrjSeKPmh8thGrlgG8V664hN8sFiFH1DvvgPt0qExJ8CiUS7UNmb-puIHWzOsd_ariAZqy1VC42MNW6Cv7RM82XbvMzKJhq0L-c_jNhm9eC4LLRuOOmOUzfnu5y7G6lrokykY509xkFCItRUGkMnkztY0jsR_txcNY-2d-dw7c4ODmwvkbncU4uHsqRZFISmJMJZh7mT-ElMscT9qgokAxoBzfIJys6UxEq_FZSId59Ma_JADJa3NlLREJfH_xSh7yapehswscwJ7X9zpm8VZhH2tNhaJPGxWdpsfL6-c168aq-1Hhr3nTnDl-oaDy74WEZrZpf0pNDPg5XNYaiSD0B21_94iDepmctP2ujX2q9VEcYUnxE9AmjeoZpprNOJBtHummQ7NWjpNn9_2SE8NnNSLUK4MQmsUYxArah9sQBun_C11iCJ6y.LEzjjZPLOkTqr50uG3TGDw

JWE包含

***** decryptKey Key ***********

shared secret HEX : DD38DD7C428A646408F3FD51622218C9AB0302F2272325C0C911EFEDDCDDB933

decryptKey: 7870587378667746306E6A38676F54727A533738454B387642327A4F6E5A4758

***** decryptKey Key ***********

jwe.getHeaderJsonEncoded(): ew0KICAiYWxnIiA6ICJBMjU2R0NNS1ciLA0KICAiaXYiIDogIlRNa2hjbkJZU082V2pueGEiLA0KICAidGFnIiA6ICJtelZqQjZ5aE5FVDEwTVYtYlp6U1lnIiwNCiAgImVuYyIgOiAiQTI1NkdDTSIsDQogICJ0eXAiIDogIkpPU0UiLA0KICAia2lkIiA6ICJGREpNUE8zQllLTldUTFFON1JCNDEzRFRQUzhPNlBuZzBYc2pPU3BobTI1MEFxMWtBIiwNCiAgImNoYW5uZWxTZWN1cml0eUNvbnRleHQiIDogIlNIQVJFRF9TRUNSRVQiLA0KICAiaWF0IiA6ICIxNTY5ODM4OTM2Ig0KfQ

***** decryptData  ***********

dataSalt IV    : JTS4C7mnDsUKundm

dataSalt IV HEX   : 2534B80BB9A70EC50ABA7766

data decoded CipherText  HEX : D36D97CF8936C541602B15700877706A526B8D278A3E687CB611AB9601BC57AEB884DF2C162147D43BEF80FB74A84C49F028944BB50D99BFA9B881D6CCEB1DFDAAE2019AB2D550B8D8C356E82BFB44CF365DBBCCCCA261AB42FE73F8CD866F5E0B82CB46E38E98E5337E7BB9CBB1BA96BA24CA4639D3DC6414222D4541A4327933B58D23B11FEDC5C358FB677E770EDCE0E0E6C2F91B9DC538B87B2A4591484A624C25987B993F8494CB1C4FDAA0A24031A01CDF209CACE94C44ABF159488779F4C6BF2400C96B73652D11097C7FF14A1EF26A97A1B30B1CC09ED7F73A66F156611F6B4D85A24F1B159DA6C7CBEBE735EBC6AAFB51E1AF79D39C397EA1A0F2EF858466B6697F4A4D0CF8395CD61A8920F4076D7FF788837A999CB4FDAE8D7DAAF5511C6149F113D0268DEA19A69ACD38906D1EE9A643B3568E9367F7FD9213C3673522D42B83109AC518C40ADA87DB1006E9FF0B5D62089EB2

data CipherText   : 022Xz4k2xUFgKxVwCHdwalJrjSeKPmh8thGrlgG8V664hN8sFiFH1DvvgPt0qExJ8CiUS7UNmb-puIHWzOsd_ariAZqy1VC42MNW6Cv7RM82XbvMzKJhq0L-c_jNhm9eC4LLRuOOmOUzfnu5y7G6lrokykY509xkFCItRUGkMnkztY0jsR_txcNY-2d-dw7c4ODmwvkbncU4uHsqRZFISmJMJZh7mT-ElMscT9qgokAxoBzfIJys6UxEq_FZSId59Ma_JADJa3NlLREJfH_xSh7yapehswscwJ7X9zpm8VZhH2tNhaJPGxWdpsfL6-c168aq-1Hhr3nTnDl-oaDy74WEZrZpf0pNDPg5XNYaiSD0B21_94iDepmctP2ujX2q9VEcYUnxE9AmjeoZpprNOJBtHummQ7NWjpNn9_2SE8NnNSLUK4MQmsUYxArah9sQBun_C11iCJ6y

dataAuthTag: LEzjjZPLOkTqr50uG3TGDw

dataAuthTag HEX : 2C4CE38D93CB3A44EAAF9D2E1B74C60F

AAD HEX : 6577304B494341695957786E4969413649434A424D6A553252304E4E533163694C41304B494341696158596949446F67496C524E6132686A626B4A5A5530383256327075654745694C41304B494341696447466E4969413649434A74656C5A71516A5A35614535465644457754565974596C703655316C6E4969774E43694167496D5675597949674F694169515449314E6B64445453497344516F6749434A306558416949446F67496B7050553055694C41304B4943416961326C6B4969413649434A475245704E5545387A516C6C4C546C64555446464F4E314A434E44457A52465251557A68504E6C42755A7A4259633270505533426F625449314D4546784D5774424969774E43694167496D4E6F595735755A5778545A574E31636D6C3065554E76626E526C6548516949446F67496C4E4951564A465246395452554E53525651694C41304B494341696157463049694136494349784E5459354F444D344F544D324967304B6651



***** decryptData ***********

decrypted: {"accountNumber":"1234567812345678","provider":{"clientAppID":"com-latuabancaperandroid","clientDeviceID":"MTcwNTMxMDEwNzAwMzQ0OTA0","clientWalletProvider":"40010043095","clientWalletAccountID":"eCdcnZmATraNmO6ToS2hzg","isIDnV":"false","Intent":"PUSH_PROV_MOBILE"},"billingAddress":{"country":"IT"},"expirationDate":{"month":"10","year":"2022"}}

shared_secret密钥是 5foz3ZBrufi2JzmKgoLO6Av7pu4btFGY5iE@uFm0

在Java中,我们可以使用Nimbus JOSE + JWT库对其进行解密。其代码如下

import com.nimbusds.jose.*;
import com.nimbusds.jose.crypto.AESDecrypter;
import com.nimbusds.jose.crypto.DirectDecrypter;
import com.nimbusds.jose.crypto.RSADecrypter;
import com.nimbusds.jose.crypto.RSAEncrypter;

import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import java.io.UnsupportedEncodingException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import java.text.ParseException;

public class TestNimbus {
    public static void main(String[] args) throws NoSuchAlgorithmException, JOSEException, ParseException, UnsupportedEncodingException {

        String sharedSecret = "5foz3ZBrufi2JzmKgoLO6Av7pu4btFGY5iE@uFm0";
        MessageDigest md = MessageDigest.getInstance("SHA-256");
        byte[] digest = md.digest(sharedSecret.getBytes("UTF-8"));

        String json = "";


        JWEObject jwe = JWEObject.parse("ew0KICAiYWxnIiA6ICJBMjU2R0NNS1ciLA0KICAiaXYiIDogIlRNa2hjbkJZU082V2pueGEiLA0KICAidGFnIiA6ICJtelZqQjZ5aE5FVDEwTVYtYlp6U1lnIiwNCiAgImVuYyIgOiAiQTI1NkdDTSIsDQogICJ0eXAiIDogIkpPU0UiLA0KICAia2lkIiA6ICJGREpNUE8zQllLTldUTFFON1JCNDEzRFRQUzhPNlBuZzBYc2pPU3BobTI1MEFxMWtBIiwNCiAgImNoYW5uZWxTZWN1cml0eUNvbnRleHQiIDogIlNIQVJFRF9TRUNSRVQiLA0KICAiaWF0IiA6ICIxNTY5ODM4OTM2Ig0KfQ.pL9EOdzwq65L3OMIPd3x5YBlZgeXXmPbqlBg2ch7w0E.JTS4C7mnDsUKundm.022Xz4k2xUFgKxVwCHdwalJrjSeKPmh8thGrlgG8V664hN8sFiFH1DvvgPt0qExJ8CiUS7UNmb-puIHWzOsd_ariAZqy1VC42MNW6Cv7RM82XbvMzKJhq0L-c_jNhm9eC4LLRuOOmOUzfnu5y7G6lrokykY509xkFCItRUGkMnkztY0jsR_txcNY-2d-dw7c4ODmwvkbncU4uHsqRZFISmJMJZh7mT-ElMscT9qgokAxoBzfIJys6UxEq_FZSId59Ma_JADJa3NlLREJfH_xSh7yapehswscwJ7X9zpm8VZhH2tNhaJPGxWdpsfL6-c168aq-1Hhr3nTnDl-oaDy74WEZrZpf0pNDPg5XNYaiSD0B21_94iDepmctP2ujX2q9VEcYUnxE9AmjeoZpprNOJBtHummQ7NWjpNn9_2SE8NnNSLUK4MQmsUYxArah9sQBun_C11iCJ6y.LEzjjZPLOkTqr50uG3TGDw");
        jwe.decrypt(new AESDecrypter(digest));
        System.out.println(jwe.getPayload().toString());
    }
}

0 个答案:

没有答案