title: How to decrypt webhook response data in Microsoft Graph?
body: <p>I have implemented Secure Web hook features for my Spring Boot application(Java).</p>
  
  <p>For that I have created "Subscription" with below JSON.</p>
  
  <pre><code>String subscriptionMessageTemplate = "{\"changeType\": \"created,updated\",\"notificationUrl\": \"%s/notify/messages\",\"lifecycleNotificationUrl\":\"%s/notify/messages/lifeCycle\", \"resource\": \"/teams/{id}/channels/19:{id}@thread.skype/messages\", \"clientState\": \"secretClientValue\",\"includeResourceData\": true,\"encryptionCertificate\": \"%s\",\"expirationDateTime\":\"%s\",\"encryptionCertificateId\": \"1\"}";
  </code></pre>
  
  <p>I have used ngrok for public IP:
  <a href="https://i.stack.imgur.com/SaY2Q.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SaY2Q.png" alt="enter image description here"></a></p>
  
  <p>When I am sending message from the team, I am getting below response.</p>
  
  <pre><code>{
      "value": [
          {
              "subscriptionId": "76222963-cc7b-42d2-882d-8aaa69cb2ba3",
              "changeType": "created",
              // Other properties typical in a resource change notification
              "resource": "teams('d29828b8-c04d-4e2a-b2f6-07da6982f0f0')/channels('19:f127a8c55ad949d1a238464d22f0f99e@thread.skype')/messages('1565045424600')/replies('1565047490246')",
              "resourceData": {
                  "id": "1565293727947",
                  "@odata.type": "#Microsoft.Graph.ChatMessage",
                  "@odata.id": "teams('88cbc8fc-164b-44f0-b6a6-b59b4a1559d3')/channels('19:8d9da062ec7647d4bb1976126e788b47@thread.tacv2')/messages('1565293727947')/replies('1565293727947')"
              },
              "encryptedContent": {
                  "data": "{encrypted data that produces a full resource}",
          "dataSignature": "&lt;HMAC-SHA256 hash&gt;",
                  "dataKey": "{encrypted symmetric key from Microsoft Graph}",
                  "encryptionCertificateId": "MySelfSignedCert/DDC9651A-D7BC-4D74-86BC-A8923584B0AB",
                  "encryptionCertificateThumbprint": "07293748CC064953A3052FB978C735FB89E61C3D"
              }
          }
      ],
      "validationTokens": [
          "eyJ0eXAiOiJKV1QiLCJhbGciOiJSU..."
      ]
  }
  </code></pre>
  
  <p>Now I want to decrypt data, Can any one help me to how to decrypt data in Java?
  For certificate generation, I have used my custom method:
  strong text.</p>
  
  <pre><code> private void generateSelfSignedX509Certificate(KeyPair keyPair) throws Exception {
  
      // yesterday
      Date validityBeginDate = new Date(System.currentTimeMillis() - 24 * 60 * 60 * 1000);
      // in 2 years
      Date validityEndDate = new Date(System.currentTimeMillis() + 2 * 365 * 24 * 60 * 60 * 1000);
  
      // GENERATE THE X509 CERTIFICATE
      X509V1CertificateGenerator certGen = new X509V1CertificateGenerator();
      X500Principal dnName = new X500Principal("CN=John Doe");
  
      certGen.setSerialNumber(BigInteger.valueOf(System.currentTimeMillis()));
      certGen.setSubjectDN(dnName);
      certGen.setIssuerDN(dnName); // use the same
      certGen.setNotBefore(validityBeginDate);
      certGen.setNotAfter(validityEndDate);
      certGen.setPublicKey(keyPair.getPublic());
      certGen.setSignatureAlgorithm("SHA256WithRSAEncryption");
  
      this.certificate = certGen.generate(keyPair.getPrivate(), "BC");
  }
  </code></pre>