Encryptors are supported via the GordianEncryptorFactory interface.
Algorithms are represented by GordianEncryptorSpec. A GordianEncryptor is obtained via the encryptorSpec, and then messages are encrypted/decrypted by the encryptor.
/* Access factory */ final GordianFactory myBaseFactory = GordianGenerator.createFactory(); final GordianKeyPairFactory myKeyPairFactory = myBase.getKeyPairFactory(); final GordianEncryptorFactory myEncryptorFactory = myKeyPairFactory.getEncryptorFactory(); /* Access keyPairGenerator */ final GordianKeyPairSpec mySpec = GordianKeyPairSpec.rsa(GordianRSAModulus.MOD2048); final GordianKeyPairGenerator myGenerator = myKeyPairFactory.getKeyPairGenerator(mySpec); final GordianKeyPair myPair = myGenerator.generateKeyPair(); /* Access encryptor */ final GordianEncryptorSpec myEncryptSpec = GordianEncryptorSpec.rsa(GordianDigestSpec.sha2(GordianLength.LEN_256)); final GordianEncryptor myEncryptor = myEncryptorFactory.createEncryptor(myEncryptSpec); /* Encrypt message */ final byte[] message = ....; myEncryptor.initForEncrypt(myPair); final byte[] myEncrypted = myEncryptor.encrypt(myMessage); /* Decrypt message */ myEncryptor.initForDecrypt(myPair); final byte[] myResult = myEncryptor.decrypt(myEncrypted);
Composite encryptions may be created by a composite keyPair, as long as each element of the composite keyPair is assigned a valid encryptorSpec.
/* Access factory */ final GordianFactory myBaseFactory = GordianGenerator.createFactory(); final GordianKeyPairFactory myKeyPairFactory = myBase.getKeyPairFactory(); final GordianEncryptorFactory myEncryptorFactory = myKeyPairFactory.getEncryptorFactory(); /* Access keyPairGenerator */ final GordianKeyPairSpec mySpec = GordianKeyPairSpec.composite(GordianKeyPairSpec.rsa(GordianRSAModulus.MOD2048), GordianKeyPairSpec.elGamal(GordianDHGroup.rfc7919_ffdhe2048)); final GordianKeyPairGenerator myGenerator = myKeyPairFactory.getKeyPairGenerator(mySpec); final GordianKeyPair myPair = myGenerator.generateKeyPair(); /* Access encryptor */ final GordianEncryptorSpec myEncryptSpec = GordianEncryptorSpec.composite(GordianEncryptorSpec.rsa(GordianDigestSpec.sha2(GordianLength.LEN_256)), GordianEncryptorSpec.elGamal(GordianDigestSpec.sha2(GordianLength.LEN_256))); final GordianEncryptor myEncryptor = myEncryptorFactory.createEncryptor(myEncryptSpec); /* Encrypt message */ final byte[] message = ....; myEncryptor.initForEncrypt(myPair); final byte[] myEncrypted = myEncryptor.encrypt(myMessage); /* Decrypt message */ myEncryptor.initForDecrypt(myPair); final byte[] myResult = myEncryptor.decrypt(myEncrypted);
The following encryptor algorithms are supported
Algorithm | Variants | Notes |
---|---|---|
RSA | SHA224, SHA256, SHA384, SHA512 | |
ElGamal | SHA224, SHA256, SHA384, SHA512 | |
EC | Available for EC, GOST2012 and SM2 keys, Not available for JCA | |
SM2 | C1C2C3, C1C3C2 | Available for EC, GOST2012 and SM2 keys |