iam无法使用nimbus库文件创建预期的jwe令牌

uqxowvwt  于 2021-08-25  发布在  Java
关注(0)|答案(0)|浏览(173)

我正在使用java代码使用nimbus jar文件生成jwe令牌,但是我无法生成预期的头jwe令牌,请你们在这里帮助我生成预期的令牌。

static String  PUBLIC_KEY ="askjdbaskjbdjkasbkjdbaskjbdasjkbdkjsabdjkaskjdbaskjdbaskjbd";
public static void main(){
    JSONObject obj = new JSONObject();
        obj.put("typ", "JWT");
        obj.put("cty", "JWT");
        obj.put("enc", "A128CBC-HS256");
        obj.put("alg", "RSA-OAEP");

//      JWEHeader head = (JWEHeader) Header.parse(JSON);
        JWEHeader header = JWEHeader.parse(obj);
        System.out.println(header.getContentType());
        JWEObject jwe = new JWEObject(header,new Payload("Hello, world!"));
        EncryptionMethod enc = EncryptionMethod.A128CBC_HS256;
        KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");
        keyGenerator.init(enc.cekBitLength());
        SecretKey cek = keyGenerator.generateKey();
            jwe.encrypt(new RSAEncrypter(getPublicKey(PUBLIC_KEY),cek));
            String jweString = jwe.serialize();
            System.out.println(jweString);
}

当我生成令牌时,我得到如下令牌:

eyJjdHkiOiJKV1QiLCJ0eXAiOiJKV1QiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2IiwiYWxnIjoiUlNBLU9BRVAifQ.ITv2i07ctBtWR8T6D63yyHE7QXIw5paeYpLYYGjN2wx9Pq5IBiYxWJBNoynZyCSC-MSFiTl55EOs1mB1qCjz0z2f25DFsnDocHJ7xNfmL5_slRCpdJX-InTcVm4NSnU2iVxaxAP5ODFrlJIgLCqICMq0MaAT8wSXAkaoVJx6MH9MRmhJzsdxCvoZaj5lu83HSL_FEveVvXt4Bk3Zq9DipVPlcbog5t1I8We8tscMW6QsOM47xxIQxmQscHOkufFkMCQOUi-LwFu4k7f6vIcASc3jbJ9VwGCPehIef0PjwQPxiO7W8tmKjcIeAF6ytYUC2nEPUwpsMZVNIaGcNPSU-w.22YugdfNWVlHWJS3OR8aiQ.S1anurm9Dim2-lV5QbNvAA.Dvfn31gFhqKbkoU3ZVGNXQ

但是header是这样生成的,但是我不希望jwe令牌中出现这种类型的header:

eyJjdHkiOiJKV1QiLCJ0eXAiOiJKV1QiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2IiwiYWxnIjoiUlNBLU9BRVAifQ

我想使用上面的java代码生成这样的头:

eyJ0eXAiOiJKV1QiLCJjdHkiOiJKV1QiLCJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkExMjhDQkMtSFMyNTYifQ

你们能帮我生成上面的标题吗。
谢谢

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题