# KeySpec

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

# KeySpec

```
interface KeySpec
```

|----------------------------------------------------------------------------------------------------------|
| [java.security.spec.KeySpec](https://developer.android.com/reference/kotlin/java/security/spec/KeySpec#) |

|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Known Direct Subclasses [DESKeySpec](https://developer.android.com/reference/kotlin/javax/crypto/spec/DESKeySpec.html#),[DESedeKeySpec](https://developer.android.com/reference/kotlin/javax/crypto/spec/DESedeKeySpec.html#),[DHPrivateKeySpec](https://developer.android.com/reference/kotlin/javax/crypto/spec/DHPrivateKeySpec.html#),[DHPublicKeySpec](https://developer.android.com/reference/kotlin/javax/crypto/spec/DHPublicKeySpec.html#),[DSAPrivateKeySpec](https://developer.android.com/reference/kotlin/java/security/spec/DSAPrivateKeySpec),[DSAPublicKeySpec](https://developer.android.com/reference/kotlin/java/security/spec/DSAPublicKeySpec),[ECPrivateKeySpec](https://developer.android.com/reference/kotlin/java/security/spec/ECPrivateKeySpec),[ECPublicKeySpec](https://developer.android.com/reference/kotlin/java/security/spec/ECPublicKeySpec),[EdECPrivateKeySpec](https://developer.android.com/reference/kotlin/java/security/spec/EdECPrivateKeySpec),[EdECPublicKeySpec](https://developer.android.com/reference/kotlin/java/security/spec/EdECPublicKeySpec),[EncodedKeySpec](https://developer.android.com/reference/kotlin/java/security/spec/EncodedKeySpec),[KeyInfo](https://developer.android.com/reference/kotlin/android/security/keystore/KeyInfo.html#), and 6 others. |-------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | [DESKeySpec](https://developer.android.com/reference/kotlin/javax/crypto/spec/DESKeySpec.html#)             | This class specifies a DES key.                                                                                                                                                                                       | | [DESedeKeySpec](https://developer.android.com/reference/kotlin/javax/crypto/spec/DESedeKeySpec.html#)       | This class specifies a DES-EDE ("triple-DES") key.                                                                                                                                                                    | | [DHPrivateKeySpec](https://developer.android.com/reference/kotlin/javax/crypto/spec/DHPrivateKeySpec.html#) | This class specifies a Diffie-Hellman private key with its associated parameters.                                                                                                                                     | | [DHPublicKeySpec](https://developer.android.com/reference/kotlin/javax/crypto/spec/DHPublicKeySpec.html#)   | This class specifies a Diffie-Hellman public key with its associated parameters.                                                                                                                                      | | [DSAPrivateKeySpec](https://developer.android.com/reference/kotlin/java/security/spec/DSAPrivateKeySpec)    | This class specifies a DSA private key with its associated parameters.                                                                                                                                                | | [DSAPublicKeySpec](https://developer.android.com/reference/kotlin/java/security/spec/DSAPublicKeySpec)      | This class specifies a DSA public key with its associated parameters.                                                                                                                                                 | | [ECPrivateKeySpec](https://developer.android.com/reference/kotlin/java/security/spec/ECPrivateKeySpec)      | This immutable class specifies an elliptic curve private key with its associated parameters.                                                                                                                          | | [ECPublicKeySpec](https://developer.android.com/reference/kotlin/java/security/spec/ECPublicKeySpec)        | This immutable class specifies an elliptic curve public key with its associated parameters.                                                                                                                           | | [EdECPrivateKeySpec](https://developer.android.com/reference/kotlin/java/security/spec/EdECPrivateKeySpec)  | A class representing elliptic curve private keys as defined in[RFC 8032: Edwards-Curve Digital Signature Algorithm (EdDSA)](https://tools.ietf.org/html/rfc8032), including the curve and other algorithm parameters. | | [EdECPublicKeySpec](https://developer.android.com/reference/kotlin/java/security/spec/EdECPublicKeySpec)    | A class representing elliptic curve public keys as defined in[RFC 8032: Edwards-Curve Digital Signature Algorithm (EdDSA)](https://tools.ietf.org/html/rfc8032), including the curve and other algorithm parameters.  | | [EncodedKeySpec](https://developer.android.com/reference/kotlin/java/security/spec/EncodedKeySpec)          | This class represents a public or private key in encoded format.                                                                                                                                                      | | [KeyInfo](https://developer.android.com/reference/kotlin/android/security/keystore/KeyInfo.html#)           | Information about a key from the[Android Keystore system](https://developer.android.com/training/articles/keystore.html).                                                                                             | | [PBEKeySpec](https://developer.android.com/reference/kotlin/javax/crypto/spec/PBEKeySpec.html#)             | A user-chosen password that can be used with password-based encryption (*PBE*).                                                                                                                                       | | [RSAPrivateKeySpec](https://developer.android.com/reference/kotlin/java/security/spec/RSAPrivateKeySpec)    | This class specifies an RSA private key.                                                                                                                                                                              | | [RSAPublicKeySpec](https://developer.android.com/reference/kotlin/java/security/spec/RSAPublicKeySpec)      | This class specifies an RSA public key.                                                                                                                                                                               | | [SecretKeySpec](https://developer.android.com/reference/kotlin/javax/crypto/spec/SecretKeySpec.html#)       | This class specifies a secret key in a provider-independent fashion.                                                                                                                                                  | | [XECPrivateKeySpec](https://developer.android.com/reference/kotlin/java/security/spec/XECPrivateKeySpec)    | A class representing elliptic curve private keys as defined in RFC 7748, including the curve and other algorithm parameters.                                                                                          | | [XECPublicKeySpec](https://developer.android.com/reference/kotlin/java/security/spec/XECPublicKeySpec)      | A class representing elliptic curve public keys as defined in RFC 7748, including the curve and other algorithm parameters.                                                                                           | |

|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Known Indirect Subclasses [PKCS8EncodedKeySpec](https://developer.android.com/reference/kotlin/java/security/spec/PKCS8EncodedKeySpec),[RSAMultiPrimePrivateCrtKeySpec](https://developer.android.com/reference/kotlin/java/security/spec/RSAMultiPrimePrivateCrtKeySpec),[RSAPrivateCrtKeySpec](https://developer.android.com/reference/kotlin/java/security/spec/RSAPrivateCrtKeySpec),[X509EncodedKeySpec](https://developer.android.com/reference/kotlin/java/security/spec/X509EncodedKeySpec),[XdhKeySpec](https://developer.android.com/reference/kotlin/android/crypto/hpke/XdhKeySpec.html#) |------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | [PKCS8EncodedKeySpec](https://developer.android.com/reference/kotlin/java/security/spec/PKCS8EncodedKeySpec)                       | This class represents the ASN.                                                                                                                                                                                   | | [RSAMultiPrimePrivateCrtKeySpec](https://developer.android.com/reference/kotlin/java/security/spec/RSAMultiPrimePrivateCrtKeySpec) | This class specifies an RSA multi-prime private key, as defined in the[PKCS#1 v2.2](https://tools.ietf.org/rfc/rfc8017.txt)standard using the Chinese Remainder Theorem (CRT) information values for efficiency. | | [RSAPrivateCrtKeySpec](https://developer.android.com/reference/kotlin/java/security/spec/RSAPrivateCrtKeySpec)                     | This class specifies an RSA private key, as defined in the[PKCS#1 v2.2](https://tools.ietf.org/rfc/rfc8017.txt)standard, using the Chinese Remainder Theorem (CRT) information values for efficiency.            | | [X509EncodedKeySpec](https://developer.android.com/reference/kotlin/java/security/spec/X509EncodedKeySpec)                         | This class represents the ASN.                                                                                                                                                                                   | | [XdhKeySpec](https://developer.android.com/reference/kotlin/android/crypto/hpke/XdhKeySpec.html#)                                  | External Diffie--Hellman (XDH) key spec holding either a public or private key.                                                                                                                                  | |

A (transparent) specification of the key material that constitutes a cryptographic key.

If the key is stored on a hardware device, its specification may contain information that helps identify the key on the device.

A key may be specified in an algorithm-specific way, or in an algorithm-independent encoding format (such as ASN.1). For example, a DSA private key may be specified by its components`x`,`p`,`q`, and`g`(see[DSAPrivateKeySpec](https://developer.android.com/reference/kotlin/java/security/spec/DSAPrivateKeySpec)), or it may be specified using its DER encoding (see[PKCS8EncodedKeySpec](https://developer.android.com/reference/kotlin/java/security/spec/PKCS8EncodedKeySpec)).

This interface contains no methods or constants. Its only purpose is to group (and provide type safety for) all key specifications. All key specifications must implement this interface.

## Summary