JHyun398998 (Community Member) asked a question.

CWE-321 Use of Hard-coded Cryptographic Key for Java SecretKeySpec

Hi all. The following pseudo code gets flagged by Veracode with CWE-321

 

public void setSecretKey(String secretKey) {

  SecretKey key = new SecretKeySpec(secretKey.getBytes(), "AES");

  ...

}

 

but this does not

 

public void setSecretKey(String secretKey) {

  byte[] bytes = secretKey.getBytes();

  SecretKey key = new SecretKeySpec(bytes, "AES");

  ...

}

 

It is not clear to me why one has a vulnerability and the other does not.


    • JHyun398998 (Community Member)

      HI @Florian, Security Consultant (Veracode)​ , I sent an email to support@veracode.com with the information you requested. An automatic support case was created and I got a reply today saying:

       

      "If you have questions regarding your scan results, you may schedule a consultation call with our Application Security Consultant team via the 'Schedule a Consultation' button found on your platform."

       

      We got around the issue by using the latter code sequence and so don't really need a full blown consultation. I just want an explanation why one gets flagged and the other doesn't. Also, I'm sure others would be interested in the explanation and it would be great if that could be provided as an answer to the forum question.

      Expand Post
      • Hi @JHyun398998 (Community Member)​, this is merely an automatic reply. You may always schedule a consultation for questions about scan results, but for something quick like this, a question to Support is also okay.

         

        What is gonna happen next is that someone from Support will reach out to you and will make sure all required information has been provided and then pass it to my team, the Application Security Consulting team.

         

        Thank you,

        Florian Walter

        Expand Post
      • JHyun398998 (Community Member)

        Nobody has reached out to me. Again, it's not a high priority since for whatever reason my code change made it pass the scan. I just wanted to know why it didn't pass the scan in the first place.

Topics (3)

No articles found
Loading

Ask the Community

Get answers, share a use case, discuss your favorite features, or get input from the community.