Swisspost 460d0e0780 sVote source code publication | %!s(int64=5) %!d(string=hai) anos | |
---|---|---|
.. | ||
cryptolib-api-asymmetric | %!s(int64=5) %!d(string=hai) anos | |
cryptolib-api-certificates | %!s(int64=5) %!d(string=hai) anos | |
cryptolib-api-commons | %!s(int64=5) %!d(string=hai) anos | |
cryptolib-api-digital-envelope | %!s(int64=5) %!d(string=hai) anos | |
cryptolib-api-elgamal | %!s(int64=5) %!d(string=hai) anos | |
cryptolib-api-primitives | %!s(int64=5) %!d(string=hai) anos | |
cryptolib-api-proofs | %!s(int64=5) %!d(string=hai) anos | |
cryptolib-api-scytl-keystore | %!s(int64=5) %!d(string=hai) anos | |
cryptolib-api-stores | %!s(int64=5) %!d(string=hai) anos | |
cryptolib-api-symmetric | %!s(int64=5) %!d(string=hai) anos | |
cryptolib-asymmetric | %!s(int64=5) %!d(string=hai) anos | |
cryptolib-certificates | %!s(int64=5) %!d(string=hai) anos | |
cryptolib-commons | %!s(int64=5) %!d(string=hai) anos | |
cryptolib-default-policies | %!s(int64=5) %!d(string=hai) anos | |
cryptolib-digital-envelope | %!s(int64=5) %!d(string=hai) anos | |
cryptolib-elgamal | %!s(int64=5) %!d(string=hai) anos | |
cryptolib-interoperation | %!s(int64=5) %!d(string=hai) anos | |
cryptolib-js | %!s(int64=5) %!d(string=hai) anos | |
cryptolib-js-asymmetric | %!s(int64=5) %!d(string=hai) anos | |
cryptolib-js-bitwise | %!s(int64=5) %!d(string=hai) anos | |
cryptolib-js-buildtools | %!s(int64=5) %!d(string=hai) anos | |
cryptolib-js-certificate | %!s(int64=5) %!d(string=hai) anos | |
cryptolib-js-codec | %!s(int64=5) %!d(string=hai) anos | |
cryptolib-js-digitalenvelope | %!s(int64=5) %!d(string=hai) anos | |
cryptolib-js-elgamal | %!s(int64=5) %!d(string=hai) anos | |
cryptolib-js-keystore | %!s(int64=5) %!d(string=hai) anos | |
cryptolib-js-mathematical | %!s(int64=5) %!d(string=hai) anos | |
cryptolib-js-messagedigest | %!s(int64=5) %!d(string=hai) anos | |
cryptolib-js-pbkdf | %!s(int64=5) %!d(string=hai) anos | |
cryptolib-js-policy | %!s(int64=5) %!d(string=hai) anos | |
cryptolib-js-securerandom | %!s(int64=5) %!d(string=hai) anos | |
cryptolib-js-symmetric | %!s(int64=5) %!d(string=hai) anos | |
cryptolib-js-zkproof | %!s(int64=5) %!d(string=hai) anos | |
cryptolib-mathematical | %!s(int64=5) %!d(string=hai) anos | |
cryptolib-primitives | %!s(int64=5) %!d(string=hai) anos | |
cryptolib-proofs | %!s(int64=5) %!d(string=hai) anos | |
cryptolib-scytl-keystore | %!s(int64=5) %!d(string=hai) anos | |
cryptolib-stores | %!s(int64=5) %!d(string=hai) anos | |
cryptolib-symmetric | %!s(int64=5) %!d(string=hai) anos | |
cryptolib-test-tools | %!s(int64=5) %!d(string=hai) anos | |
.gitattributes | %!s(int64=5) %!d(string=hai) anos | |
.gitignore | %!s(int64=5) %!d(string=hai) anos | |
LICENSE | %!s(int64=5) %!d(string=hai) anos | |
README.md | %!s(int64=5) %!d(string=hai) anos | |
THIRD-PARTY.txt | %!s(int64=5) %!d(string=hai) anos | |
licensePattern.xml | %!s(int64=5) %!d(string=hai) anos | |
pom.xml | %!s(int64=5) %!d(string=hai) anos |
Stored in Nexus at https://nexus.scytl.net/content/repositories/releases/com/scytl/cryptolib
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>
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;
public static void generateSecretKey() {
Security.addProvider(new BouncyCastleProvider());
SymmetricService symmetricService = new SymmetricService();
SecretKey secretKeyForEncryption = symmetricService.getSecretKeyForEncryption();
}
public static void generateSecretKeyForHMAC() {
Security.addProvider(new BouncyCastleProvider());
SymmetricService symmetricService = new SymmetricService();
SecretKey secretKeyForHMAC = symmetricService.getSecretKeyForHmac();
}
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);
}
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());
}
public static void createKeypair() {
Security.addProvider(new BouncyCastleProvider());
AsymmetricService asymmetricService = new AsymmetricService();
KeyPair keyPairForEncryption = asymmetricService.getKeyPairForEncryption();
}
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);
}
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());
}
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");
}
public static void createSignX509Certificate() {
CertificatesService certificatesService = new CertificatesService();
CertificateData userCertificate = new CertificateData();
userCertificate.setSubjectPublicKey(userKeyPair.getPublic());
certificatesService.createSignX509Certificate(userCertificate, rootKeyPair.getPrivate());
}
public static void createEncryptionX509Certificate() {
certificatesService.createEncryptionX509Certificate(userCertificate, rootKeyPair.getPrivate());
}
public static void createRootAuthorityX509Certificate() {
RootCertificateData rootCertificateData = new RootCertificateData();
rootCertificateData.setSubjectPublicKey(rootKeyPair.getPublic());
certificatesService.createRootAuthorityX509Certificate(rootCertificateData, rootKeyPair.getPrivate());
}
public static void createIntermediateAuthorityX509Certificate() {
CertificateData intermediateAuthorityCertificateData = new CertificateData();
intermediateAuthorityCertificateData.setSubjectPublicKey(intermediateAuthorityKeyPair.getPublic());
certificatesService.createIntermediateAuthorityX509Certificate(intermediateAuthorityCertificateData, rootKeyPair.getPrivate());
}