Swisspost 460d0e0780 sVote source code publication преди 5 години
..
cryptolib-api-asymmetric 460d0e0780 sVote source code publication преди 5 години
cryptolib-api-certificates 460d0e0780 sVote source code publication преди 5 години
cryptolib-api-commons 460d0e0780 sVote source code publication преди 5 години
cryptolib-api-digital-envelope 460d0e0780 sVote source code publication преди 5 години
cryptolib-api-elgamal 460d0e0780 sVote source code publication преди 5 години
cryptolib-api-primitives 460d0e0780 sVote source code publication преди 5 години
cryptolib-api-proofs 460d0e0780 sVote source code publication преди 5 години
cryptolib-api-scytl-keystore 460d0e0780 sVote source code publication преди 5 години
cryptolib-api-stores 460d0e0780 sVote source code publication преди 5 години
cryptolib-api-symmetric 460d0e0780 sVote source code publication преди 5 години
cryptolib-asymmetric 460d0e0780 sVote source code publication преди 5 години
cryptolib-certificates 460d0e0780 sVote source code publication преди 5 години
cryptolib-commons 460d0e0780 sVote source code publication преди 5 години
cryptolib-default-policies 460d0e0780 sVote source code publication преди 5 години
cryptolib-digital-envelope 460d0e0780 sVote source code publication преди 5 години
cryptolib-elgamal 460d0e0780 sVote source code publication преди 5 години
cryptolib-interoperation 460d0e0780 sVote source code publication преди 5 години
cryptolib-js 460d0e0780 sVote source code publication преди 5 години
cryptolib-js-asymmetric 460d0e0780 sVote source code publication преди 5 години
cryptolib-js-bitwise 460d0e0780 sVote source code publication преди 5 години
cryptolib-js-buildtools 460d0e0780 sVote source code publication преди 5 години
cryptolib-js-certificate 460d0e0780 sVote source code publication преди 5 години
cryptolib-js-codec 460d0e0780 sVote source code publication преди 5 години
cryptolib-js-digitalenvelope 460d0e0780 sVote source code publication преди 5 години
cryptolib-js-elgamal 460d0e0780 sVote source code publication преди 5 години
cryptolib-js-keystore 460d0e0780 sVote source code publication преди 5 години
cryptolib-js-mathematical 460d0e0780 sVote source code publication преди 5 години
cryptolib-js-messagedigest 460d0e0780 sVote source code publication преди 5 години
cryptolib-js-pbkdf 460d0e0780 sVote source code publication преди 5 години
cryptolib-js-policy 460d0e0780 sVote source code publication преди 5 години
cryptolib-js-securerandom 460d0e0780 sVote source code publication преди 5 години
cryptolib-js-symmetric 460d0e0780 sVote source code publication преди 5 години
cryptolib-js-zkproof 460d0e0780 sVote source code publication преди 5 години
cryptolib-mathematical 460d0e0780 sVote source code publication преди 5 години
cryptolib-primitives 460d0e0780 sVote source code publication преди 5 години
cryptolib-proofs 460d0e0780 sVote source code publication преди 5 години
cryptolib-scytl-keystore 460d0e0780 sVote source code publication преди 5 години
cryptolib-stores 460d0e0780 sVote source code publication преди 5 години
cryptolib-symmetric 460d0e0780 sVote source code publication преди 5 години
cryptolib-test-tools 460d0e0780 sVote source code publication преди 5 години
.gitattributes 460d0e0780 sVote source code publication преди 5 години
.gitignore 460d0e0780 sVote source code publication преди 5 години
LICENSE 460d0e0780 sVote source code publication преди 5 години
README.md 460d0e0780 sVote source code publication преди 5 години
THIRD-PARTY.txt 460d0e0780 sVote source code publication преди 5 години
licensePattern.xml 460d0e0780 sVote source code publication преди 5 години
pom.xml 460d0e0780 sVote source code publication преди 5 години

README.md

Cryptolib-Java - A quick start to the Scytl cryptographic library implemented in Java

Released artifacts

Stored in Nexus at https://nexus.scytl.net/content/repositories/releases/com/scytl/cryptolib

Maven setup

Dependency on cryptoLib can be specific to a module:

<dependency>
  <artifactId>cryptolib-api-symmetric</artifactId>
  <groupId>com.scytl.cryptolib</groupId>
  <version>${cryptolib.version}</version>
</dependency>

or generic:

<dependency>
  <artifactId>cryptolib-all</artifactId>
  <groupId>com.scytl.cryptolib</groupId>
  <version>${cryptolib.version}</version>
</dependency>

Java imports

Theses examples apply to subsequent code snippets provided.

import java.security.Security;
import java.security.KeyPair;
import java.io.FileInputStream;
import javax.crypto.SecretKey;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import com.scytl.cryptolib.symmetric.service.SymmetricService;
import com.scytl.cryptolib.asymmetric.service.AsymmetricService;
import com.scytl.cryptolib.certificates.service.CertificatesService;
import com.scytl.cryptolib.certificates.bean.CertificateData;
import com.scytl.cryptolib.certificates.bean.RootCertificateData;

Symmetric service

How to getSecretKeyForEncryption

public static void generateSecretKey() {
  Security.addProvider(new BouncyCastleProvider());
  SymmetricService symmetricService = new SymmetricService();
  SecretKey secretKeyForEncryption = symmetricService.getSecretKeyForEncryption();
}

How to getSecretKeyForHmac

public static void generateSecretKeyForHMAC() {
  Security.addProvider(new BouncyCastleProvider());
  SymmetricService symmetricService = new SymmetricService();
  SecretKey secretKeyForHMAC = symmetricService.getSecretKeyForHmac();
}

How to encrypt and decrypt

public static void encryptAndDecryptSymmetric() {
  Security.addProvider(new BouncyCastleProvider());
  SymmetricService symmetricService = new SymmetricService();
  byte[] encryptedData = symmetricService.encrypt(secretKeyForEncryption, plainText.getBytes());
  byte[] decryptedData = symmetricService.decrypt(secretKeyForEncryption, encryptedData);
}

How to getMac and verifyMac

public static void getAndVerifyHMAC() {
  Security.addProvider(new BouncyCastleProvider());
  SymmetricService symmetricService = new SymmetricService();
  byte[] mac = symmetricService.getMac(secretKeyForHMAC, plainText.getBytes());
  boolean verificationResult = symmetricService.verifyMac(secretKeyForHMAC, mac, plainText.getBytes());
}

Asymmetric service

How to getKeyPairForEncryption

public static void createKeypair() {
  Security.addProvider(new BouncyCastleProvider());
  AsymmetricService asymmetricService = new AsymmetricService();
  KeyPair keyPairForEncryption = asymmetricService.getKeyPairForEncryption();
}

How to encrypt and decrypt

public static void encryptAndDecryptAsymmetric() {
  Security.addProvider(new BouncyCastleProvider());
  AsymmetricService asymmetricService = new AsymmetricService();
  byte[] encryptedData = asymmetricService.encrypt(keyPairForEncryption.getPublic(), plainText.getBytes());
  byte[] decryptedData = asymmetricService.decrypt(keyPairForEncryption.getPrivate(), encryptedData);
}

How to sign and verifySignature

public static void signAndVerifySignature() {
  Security.addProvider(new BouncyCastleProvider());
  AsymmetricService asymmetricService = new AsymmetricService();
  KeyPair keyPairForSigning = asymmetricService.getKeyPairForSigning();
  byte[] signatureBytes = asymmetricService.sign(keyPairForSigning.getPrivate(), plainText.getBytes());
  boolean verificationResult = asymmetricService.verifySignature(signatureBytes, keyPairForSigning.getPublic(), plainText.getBytes());
}

How to verifyXmlSignature

public static void verifyXmlSignature() {
  Security.addProvider(new BouncyCastleProvider());
  AsymmetricService asymmetricService = new AsymmetricService();
  FileInputStream signedXmlInStream = new FileInputStream(signedXmlFile);
  boolean verificationResult = asymmetricService.verifyXmlSignature(keyPairForSigning.getPublic(), signedXmlInStream, "xmlNodeNameSigned");
}

Certificates service

How to createSignX509Certificate

public static void createSignX509Certificate() {
  CertificatesService certificatesService = new CertificatesService();
  CertificateData userCertificate = new CertificateData();
  userCertificate.setSubjectPublicKey(userKeyPair.getPublic());
  certificatesService.createSignX509Certificate(userCertificate, rootKeyPair.getPrivate());
}

How to createEncryptionX509Certificate

public static void createEncryptionX509Certificate() {
  certificatesService.createEncryptionX509Certificate(userCertificate, rootKeyPair.getPrivate());
}

How to createRootAuthorityX509Certificate

public static void createRootAuthorityX509Certificate() {
  RootCertificateData rootCertificateData = new RootCertificateData();
  rootCertificateData.setSubjectPublicKey(rootKeyPair.getPublic());
  certificatesService.createRootAuthorityX509Certificate(rootCertificateData, rootKeyPair.getPrivate());
}

How to createIntermediateAuthorityX509Certificate

public static void createIntermediateAuthorityX509Certificate() {
  CertificateData intermediateAuthorityCertificateData = new CertificateData();
  intermediateAuthorityCertificateData.setSubjectPublicKey(intermediateAuthorityKeyPair.getPublic());
  certificatesService.createIntermediateAuthorityX509Certificate(intermediateAuthorityCertificateData, rootKeyPair.getPrivate());
}