Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Unanswered

How to encrypt PAN Number in this format using JWE Algorithm?

(0) ShareShare
ReportReport
Posted on by 5
I have a pan number in below JSON format
 
{
/pannumber/:/GUYTE6687U/
}
 
I want to encrypt and decrypt the above pannumber using Algorithm: JWEAlgorithm.A256KW  Encryption Method: A128CBC_HS25. I have the encryption/decryption code in JAVA. I want to know how to do the same in AL or using dot net.
 
Below is the JAVA code. I want the encryption with the following headings /encrypted_key/, /protected/, /ciphertext/, /iv/ and /tag/.
 
   public static void encryptRequest(JSONObject jsonObject) throws JoseException {
        Key key = new AesKey(DatatypeConverter.parseHexBinary(PRIVATE_KEY_STRING));
        JsonWebEncryption jwe = new JsonWebEncryption();
        jwe.setPayload(jsonObject.toJSONString());
        jwe.setAlgorithmHeaderValue(/A256KW/);
        jwe.setEncryptionMethodHeaderParameter(/A128CBC-HS256/);
        jwe.setKey(key);
        String serializedJwe = jwe.getCompactSerialization();
        String[] components = CompactSerializer.deserialize(serializedJwe);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put(/protected/, components[0]);
        map.put(/ciphertext/, components[3]);
        map.put(/iv/, components[2]);
        map.put(/tag/, components[4]);
        Map<String, String> encryptedKey = new HashMap<String, String>();
        encryptedKey.put(/encrypted_key/, components[1]);
        map.put(/recipients/, Arrays.asList(new Map[]{encryptedKey}));
        System.out.println(/Encrypted Text: / + JSONObject.toJSONString(map));
    }
 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,711 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,458 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans