/hmkit-crypto-java

☕️ Crypto library for Java – securing all communications in the HMKit SDK

Primary LanguageJavaMIT LicenseMIT

HMKit Crypto

This repository contains the Certificate classes and public Crypto methods(sign, keygen).

The library should be accessed from either hmkit-oem or hmkit-android. It cannot be used independently because it doesn't include the core.

Dependencies

  • hmkit-core (from either HMKit Android or HMKit OEM)
  • hmkit-utils

Setup

  • Follow the setup process in either HMKit Android or HMKit OEM projects.

Install

Releases are pushed to mavenCentral. To include hmkit-crypto in your project, add to build.gradle:

repositories {
  mavenCentral()
}

dependencies {
  // Depending on your environment, use hmkit-oem or hmkit-android to get the transitive crypto
  // dependency 
  // implementation 'com.highmobility:hmkit-oem:2.0.0'
  // or
  // implementation 'com.highmobility:hmkit-android:2.0.3@aar' { transitive = true }
}

Find the latest version names in mavenCentral

Certificates

Access Certificate and Device Certificate are represented in this library. The certificates will always be converted to raw bytes that are accessible with Bytes getBytes() method. You can always add a signature later with setSignature(Signature). You can get the certificate data without the signature with getCertificateData().

AccessCertificate

Use one of the designated initialisers to create the object. For example:

public public AccessCertificate(Issuer issuer,
                                DeviceSerial providingSerial,
                                DeviceSerial gainerSerial,
                                PublicKey gainingPublicKey,
                                HMCalendar startDate,
                                HMCalendar endDate,
                                Permissions permissions)

See public getters for certificate info, for example

public Issuer getIssuer()

DeviceCertificate

Use one of the designated initialisers to create the object. For example:

public DeviceCertificate(Issuer issuer,
                         AppIdentifier appIdentifier,
                         DeviceSerial serial,
                         PublicKey publicKey)

See public getters for certificate info, for example

public PublicKey getPublicKey()

Crypto

Use Crypto.java static methods to

create a key pair

public static HMKeyPair createKeypair()

create a random serial number

public static DeviceSerial createSerialNumber()

sign

public static Signature sign(Bytes bytes, PrivateKey privateKey)

Note that all of the Certificate fields(Issuer, DeviceSerial) inherit from custom Bytes class whose methods can be used for general initialisation, comparison and description.