- Home
-
CWE-321: Use of Hard-coded Cryptographic Key
Weakness ID: 321Vulnerability Mapping: ALLOWED This CWE ID may be used to map to real-world vulnerabilities
Abstraction: Variant Variant - a weakness that is linked to a certain type of product, typically involving a specific language or technology. More specific than a Base weakness. Variant level weaknesses typically describe issues in terms of 3 to 5 of the following dimensions: behavior, property, technology, language, and resource.View customized information:For users who are interested in more notional aspects of a weakness. Example: educators, technical writers, and project/program managers. For users who are concerned with the practical application and details about the nature of a weakness and how to prevent it from happening. Example: tool developers, security researchers, pen-testers, incident response analysts. For users who are mapping an issue to CWE/CAPEC IDs, i.e., finding the most appropriate CWE for a specific issue (e.g., a CVE record). Example: tool developers, security researchers. For users who wish to see all available information for the CWE/CAPEC entry. For users who want to customize what details are displayed.×
Edit Custom Filter
This table specifies different individual consequences
associated with the weakness. The Scope identifies the application security area that is
violated, while the Impact describes the negative technical impact that arises if an
adversary succeeds in exploiting this weakness. The Likelihood provides information about
how likely the specific consequence is expected to be seen relative to the other
consequences in the list. For example, there may be high likelihood that a weakness will be
exploited to achieve a certain impact, but a low likelihood that it will be exploited to
achieve a different impact.
Impact Details Bypass Protection Mechanism; Gain Privileges or Assume Identity; Read Application Data
Scope: Access Control If hard-coded cryptographic keys are used, it is almost certain that malicious users will gain access through the account in question. The use of a hard-coded cryptographic key significantly increases the possibility that encrypted data may be recovered.Phase(s) Mitigation Architecture and Design
Prevention schemes mirror that of hard-coded password storage.
This table shows the weaknesses and high level categories that are related to this
weakness. These relationships are defined as ChildOf, ParentOf, MemberOf and give insight to
similar items that may exist at higher and lower levels of abstraction. In addition,
relationships such as PeerOf and CanAlsoBe are defined to show similar weaknesses that the user
may want to explore.
Relevant to the view "Research Concepts" (View-1000)
Nature Type ID Name ChildOf
Base - a weakness that is still mostly independent of a resource or technology, but with sufficient details to provide specific methods for detection and prevention. Base level weaknesses typically describe issues in terms of 2 or 3 of the following dimensions: behavior, property, technology, language, and resource.
798 Use of Hard-coded Credentials PeerOf
Variant - a weakness that is linked to a certain type of product, typically involving a specific language or technology. More specific than a Base weakness. Variant level weaknesses typically describe issues in terms of 3 to 5 of the following dimensions: behavior, property, technology, language, and resource.
259 Use of Hard-coded Password PeerOf
Base - a weakness that is still mostly independent of a resource or technology, but with sufficient details to provide specific methods for detection and prevention. Base level weaknesses typically describe issues in terms of 2 or 3 of the following dimensions: behavior, property, technology, language, and resource.
1291 Public Key Re-Use for Signing both Debug and Production Code CanFollow
Class - a weakness that is described in a very abstract fashion, typically independent of any specific language or technology. More specific than a Pillar Weakness, but more general than a Base Weakness. Class level weaknesses typically describe issues in terms of 1 or 2 of the following dimensions: behavior, property, and resource.
656 Reliance on Security Through Obscurity
Relevant to the view "Architectural Concepts" (View-1008)
Nature Type ID Name MemberOf
Category - a CWE entry that contains a set of other entries that share a common characteristic.
1013 Encrypt Data
Relevant to the view "CISQ Quality Measures (2020)" (View-1305)
Nature Type ID Name ChildOf
Base - a weakness that is still mostly independent of a resource or technology, but with sufficient details to provide specific methods for detection and prevention. Base level weaknesses typically describe issues in terms of 2 or 3 of the following dimensions: behavior, property, technology, language, and resource.
798 Use of Hard-coded Credentials
Relevant to the view "CISQ Data Protection Measures" (View-1340)
Nature Type ID Name ChildOf
Base - a weakness that is still mostly independent of a resource or technology, but with sufficient details to provide specific methods for detection and prevention. Base level weaknesses typically describe issues in terms of 2 or 3 of the following dimensions: behavior, property, technology, language, and resource.
798 Use of Hard-coded Credentials
The different Modes of Introduction provide information
about how and when this
weakness may be introduced. The Phase identifies a point in the life cycle at which
introduction
may occur, while the Note provides a typical scenario related to introduction during the
given
phase.
Phase Note Architecture and Design REALIZATION: This weakness is caused during implementation of an architectural security tactic.
This listing shows possible areas for which the given
weakness could appear. These
may be for specific named Languages, Operating Systems, Architectures, Paradigms,
Technologies,
or a class of such platforms. The platform is listed along with how frequently the given
weakness appears for that instance.
Languages Class: Not Language-Specific (Undetermined Prevalence)
Technologies Class: ICS/OT (Undetermined Prevalence)
Example 1
The following code examples attempt to verify a password using a hard-coded cryptographic key.
(bad code)Example Language: Cint VerifyAdmin(char *password) {}if (strcmp(password,"68af404b513073584c4b6f22b6c63e6b")) {}
printf("Incorrect Password!\n");
return(0);
printf("Entering Diagnostic Mode...\n");
return(1);(bad code)Example Language: Javapublic boolean VerifyAdmin(String password) {if (password.equals("68af404b513073584c4b6f22b6c63e6b")) {System.out.println("Entering Diagnostic Mode...");}
return true;
System.out.println("Incorrect Password!");
return false;(bad code)Example Language: C#int VerifyAdmin(String password) {if (password.Equals("68af404b513073584c4b6f22b6c63e6b")) {}Console.WriteLine("Entering Diagnostic Mode...");}
return(1);
Console.WriteLine("Incorrect Password!");
return(0);The cryptographic key is within a hard-coded string value that is compared to the password. It is likely that an attacker will be able to read the key and compromise the system.
Example 2
In 2022, the OT:ICEFALL study examined products by 10 different Operational Technology (OT) vendors. The researchers reported 56 vulnerabilities and said that the products were "insecure by design" [REF-1283]. If exploited, these vulnerabilities often allowed adversaries to change how the products operated, ranging from denial of service to changing the code that the products executed. Since these products were often used in industries such as power, electrical, water, and others, there could even be safety implications.
Multiple vendors used hard-coded keys for critical functionality in their OT products.
Note: this is a curated list of examples for users to understand the variety of ways in which this weakness can be introduced. It is not a complete list of all CVEs that are related to this CWE entry.
Reference Description Engineering Workstation uses hard-coded cryptographic keys that could allow for unathorized filesystem access and privilege escalationRemote Terminal Unit (RTU) uses a hard-coded SSH private key that is likely to be used by default.WiFi router service has a hard-coded encryption key, allowing root accessCommunications / collaboration product has a hardcoded SSH private key, allowing access to root accountOrdinality Description Primary(where the weakness exists independent of other weaknesses)Method Details Automated Static Analysis
Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)Effectiveness: High
This MemberOf Relationships table shows additional CWE Categories and Views that
reference this weakness as a member. This information is often useful in understanding where a
weakness fits within the context of external information sources.
Nature Type ID Name MemberOf
Category - a CWE entry that contains a set of other entries that share a common characteristic.719 OWASP Top Ten 2007 Category A8 - Insecure Cryptographic Storage MemberOf
Category - a CWE entry that contains a set of other entries that share a common characteristic.720 OWASP Top Ten 2007 Category A9 - Insecure Communications MemberOf
Category - a CWE entry that contains a set of other entries that share a common characteristic.729 OWASP Top Ten 2004 Category A8 - Insecure Storage MemberOf
Category - a CWE entry that contains a set of other entries that share a common characteristic.950 SFP Secondary Cluster: Hardcoded Sensitive Data MemberOf
Category - a CWE entry that contains a set of other entries that share a common characteristic.1346 OWASP Top Ten 2021 Category A02:2021 - Cryptographic Failures MemberOf
Category - a CWE entry that contains a set of other entries that share a common characteristic.1396 Comprehensive Categorization: Access Control MemberOf
Category - a CWE entry that contains a set of other entries that share a common characteristic.1439 OWASP Top Ten 2025 Category A04:2025 - Cryptographic Failures Usage ALLOWED (this CWE ID may be used to map to real-world vulnerabilities)Reason Acceptable-Use Rationale
This CWE entry is at the Variant level of abstraction, which is a preferred level of abstraction for mapping to the root causes of vulnerabilities. Comments
Carefully read both the name and description to ensure that this mapping is an appropriate fit. Do not try to 'force' a mapping to a lower-level Base/Variant simply to comply with this preferred level of abstraction. Other
The main difference between the use of hard-coded passwords and the use of hard-coded cryptographic keys is the false sense of security that the former conveys. Many people believe that simply hashing a hard-coded password before storage will protect the information from malicious users. However, many hashes are reversible (or at least vulnerable to brute force attacks) -- and further, many authentication protocols simply request the hash itself, making it no better than a password.Mapped Taxonomy Name Node ID Fit Mapped Node Name CLASP Use of hard-coded cryptographic key OWASP Top Ten 2007 A8 CWE More Specific Insecure Cryptographic Storage OWASP Top Ten 2007 A9 CWE More Specific Insecure Communications OWASP Top Ten 2004 A8 CWE More Specific Insecure Storage Software Fault Patterns SFP33 Hardcoded sensitive data ISA/IEC 62443 Part 2-4 Req SP.03.10 RE(1) ISA/IEC 62443 Part 2-4 Req SP.03.10 RE(3) ISA/IEC 62443 Part 3-3 Req SR 1.5 ISA/IEC 62443 Part 3-3 Req SR 4.3 ISA/IEC 62443 Part 4-1 Req SD-1 ISA/IEC 62443 Part 4-2 Req SR 4.3 ISA/IEC 62443 Part 4-2 Req CR 7.3 [REF-18] Secure Software, Inc.. "The CLASP Application Security Process". 2005.
<https://cwe.mitre.org/documents/sources/TheCLASPApplicationSecurityProcess.pdf>. (URL validated: 2024-11-17)[REF-1283] Forescout Vedere Labs. "OT:ICEFALL: The legacy of "insecure by design" and its implications for certifications and risk management". 2022-06-20.
<https://www.forescout.com/resources/ot-icefall-report/>.More information is available — Please edit the custom filter or select a different filter.Page Last Updated: January 21, 2026Use of the Common Weakness Enumeration (CWE™) and the associated references from this website are subject to the Terms of Use. CWE is sponsored by the U.S. Department of Homeland Security (DHS) Cybersecurity and Infrastructure Security Agency (CISA) and managed by the Homeland Security Systems Engineering and Development Institute (HSSEDI) which is operated by The MITRE Corporation (MITRE). Copyright © 2006–2026, The MITRE Corporation. CWE, CWSS, CWRAF, and the CWE logo are trademarks of The MITRE Corporation.



