@Override public PrivateKeyPair createPrivateKeyPair(String base64) throws GeneralSecurityException { int base64PrivateKeyLength = getBase64PrivateKeyPairLength() / 2; base64 = "A" + base64.substring(0, base64PrivateKeyLength) + "A" + base64.substring(base64PrivateKeyLength); byte[] bytes = Base64.decode(base64); return createPrivateKeyPair(bytes); } }
private static void init() { instances = Collections.synchronizedList(new ArrayList<CryptoImplementation>()); Log log = new Log(CryptoFactory.class); try { instances.add(new ElGamal2048_DSA1024()); } catch (GeneralSecurityException e) { log.error("Error creating ElGamal2048_DSA1024.", e); } try { instances.add(new ECDH256_ECDSA256()); instances.add(new ECDH521_ECDSA521()); } catch (GeneralSecurityException e) { log.error("Error creating ECDH256_ECDSA256 or ECDH521_ECDSA521.", e); } try { instances.add(new NTRUEncrypt1087_GMSS512()); } catch (GeneralSecurityException e) { log.error("Error creating NTRUEncrypt1087_GMSS512.", e); } } }
@Override protected byte[] toByteArray(PublicKey key) { ECPublicKey ecKey = castToEcKey(key); byte[] bouncyCompressedKey = ECUtils.encodePoint(ecKey.getParams(), ecKey.getW(), true); // shorten by one byte (bouncyCompressedKey[0] is either 2 or 3, bouncyCompressedKey[1] is either 0 or 1, so they can fit in two bits) if (bouncyCompressedKey[0]!=2 && bouncyCompressedKey[0]!=3) log.error("Illegal value in encoded EC key at byte 0: " + bouncyCompressedKey[0] + ", can only be 2 or 3."); if (bouncyCompressedKey[1]!=0 && bouncyCompressedKey[1]!=1) log.error("Illegal value in encoded EC key at byte 1: " + bouncyCompressedKey[1] + ", can only be 0 or 1."); byte[] compressedKey = Arrays.copyOfRange(bouncyCompressedKey, 1, keyLengthBytes+1); compressedKey[0] |= (bouncyCompressedKey[0]-2) << 1; return compressedKey; }
TestIdentity ecdh521 = new TestIdentity(ecdh521PublicKeyPair, ecdh521PrivateKeyPair, new ECDH521_ECDSA521()); identities.add(ecdh521);