/** * Returns the two key pairs (public + private) as one Base64-encoded string. * @throws GeneralSecurityException */ public String getFullKey() throws GeneralSecurityException { PublicKeyPair publicKeys = new PublicKeyPair(publicEncryptionKey, publicSigningKey); PrivateKeyPair privateKeys = new PrivateKeyPair(privateEncryptionKey, privateSigningKey); String pubKeys = cryptoImpl.toBase64(publicKeys); String privKeys = cryptoImpl.toBase64(privateKeys); return pubKeys + privKeys; }
/** * Returns the two public keys in Base64 representation. */ public String getKey() { PublicKeyPair keys = new PublicKeyPair(publicEncryptionKey, publicSigningKey); try { return cryptoImpl.toBase64(keys); } catch (GeneralSecurityException e) { log.error("Can't get email destination keys.", e); return "<Error>: " + e.getLocalizedMessage(); } }
@Test public void encodeDecodeBase64() throws GeneralSecurityException { for (TestIdentity testData: testIdentities) { CryptoImplementation cryptoImpl = testData.cryptoImpl; // test a public key pair PublicKeyPair publicKeyPair = cryptoImpl.createPublicKeyPair(testData.base64PublicKeyPair); String reencodedPublic = cryptoImpl.toBase64(publicKeyPair); assertEquals(testData.base64PublicKeyPair, reencodedPublic); assertEquals("Wrong public key length!", cryptoImpl.getBase64PublicKeyPairLength(), testData.base64PublicKeyPair.length()); // test a private key pair PrivateKeyPair privateKeyPair = cryptoImpl.createPrivateKeyPair(testData.base64PrivateKeyPair); String reencodedPrivate = cryptoImpl.toBase64(privateKeyPair); assertEquals(testData.base64PrivateKeyPair, reencodedPrivate); assertEquals("Wrong private key length!", cryptoImpl.getBase64CompleteKeySetLength()-cryptoImpl.getBase64PublicKeyPairLength(), testData.base64PrivateKeyPair.length()); } }