# Overview

This library ports a subset of the standard Java API for Crypto from the Java Cryptography Architecture (JCA).
It also implements a crypto provider which fully relies on a native crypto engine and defines the SNI Low Level API to be implemented to integrate with such a native crypto engine.

It also exposes the `LLCRYPTO_*` LLAPI C headers (under `src/main/include/`) that
VEE Port natives must implement to provide cryptographic services. The legacy `LLSEC_*.h`
headers are kept as deprecated backward-compatibility shims that alias the renamed
`LLCRYPTO_*` API.

# Usage

Add the following dependency to your `build.gradle.kts`:

	implementation("ej.api:crypto:<version>")


## Exclude parts of the library to reduce the memory footprint

### BON Constants configuration

The following BON constants can be defined and set to false in an Application `resources/app.constants.list` or `common.properties` to exclude algorithms support and associated code:

#### Disable algorithms

**Ciphers**
- com.microej.security.abstract.cipher.gcm.mode.enabled (disable gcm mode for all ciphers)
- com.microej.security.cipher.generic.enabled
- com.microej.security.cipher.rsa.enabled
- com.microej.security.cipher.aeswrap.enabled
- com.microej.security.cipher.pkcs12.pbe.enabled (prevents every algorithms loading when disabled)
 - com.microej.security.cipher.pkcs12.pbe.pbe.sha1.des.ede.enabled
- com.microej.security.cipher.pbes2.enabled (prevents every algorithms loading when disabled)
 - com.microej.security.cipher.pbes2.pbe.hmac.sha1.aes128.enabled
 - com.microej.security.cipher.pbes2.pbe.hmac.sha224.aes128.enabled
 - com.microej.security.cipher.pbes2.pbe.hmac.sha256.aes128.enabled
 - com.microej.security.cipher.pbes2.pbe.hmac.sha384.aes128.enabled
 - com.microej.security.cipher.pbes2.pbe.hmac.sha512.aes128.enabled

**Factories**
- com.microej.security.native.secret.key.factory.enabled=true

**PBE Keys**
- com.microej.security.pbe.key.factory.enabled (prevents every algorithms loading when disabled))
- com.microej.security.pbe.key.factory.pbe.sha1.des.ede.enabled
- com.microej.security.pbe.key.factory.pbe.hmac.sha1.aes128.enabled
- com.microej.security.pbe.key.factory.pbe.hmac.sha224.aes128.enabled
- com.microej.security.pbe.key.factory.pbe.hmac.sha256.aes128.enabled
- com.microej.security.pbe.key.factory.pbe.hmac.sha384.aes128.enabled
- com.microej.security.pbe.key.factory.pbe.hmac.sha512.aes128.enabled

#### Disable debug

- com.microej.security.debug.enabled: when enabled, some classes override the toString() method to output more exhaustive informations. 

### Included back-ends

The following JCE providers are loaded reflectively and embedded by default. An Application can exclude an unused one to reduce its footprint by setting the Application Option `com.microej.type.<fully.qualified.class.name>.enabled` to `false` (for example in `configuration.properties`):

- com.microej.crypto.internal.x509.X509Factory
- com.microej.crypto.internal.DefaultKeyStore
- com.microej.crypto.internal.provider.ExternalKeyStoreSpi
- com.microej.crypto.internal.provider.PKIXCertPathValidator
- com.microej.crypto.internal.provider.ECDHKeyAgreement

For example, to exclude the external key store back-end:

	com.microej.type.com.microej.crypto.internal.provider.ExternalKeyStoreSpi.enabled=false


# Requirements

# Dependencies

_All dependencies are retrieved transitively by Gradle_.

# Source

The following JCA API Java source files are derived from [JDK8u442-ga](https://github.com/openjdk/jdk8u/releases/tag/jdk8u442-ga):

* `ASSEMBLY_EXCEPTION.txt`
* `LICENSE.txt`
* `java.security.cert.*`
* `javax.crypto.KeyAgreement` & `javax.crypto.KeyAgreementSPI`

# Restrictions

None.

---  
_Copyright 2014-2026 MicroEJ Corp. This file has been modified and/or created by MicroEJ Corp._
_DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER._

_This code is free software; you can redistribute it and/or modify it_
_under the terms of the GNU General Public License version 2 only, as_
_published by the Free Software Foundation.  Oracle designates this_
_particular file as subject to the "Classpath" exception as provided_
_by Oracle in the LICENSE file that accompanied this code._

_This code is distributed in the hope that it will be useful, but WITHOUT_
_ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or_
_FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License_
_version 2 for more details (a copy is included in the LICENSE file that_
_accompanied this code)._

_You should have received a copy of the GNU General Public License version_
_2 along with this work; if not, write to the Free Software Foundation,_
_Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA._

_Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA_
_or visit www.oracle.com if you need additional information or have any_
_questions._
