/** * Each supported key has a mask that represents its type. The key that has no known mask can't be processed bt the * address. * * @param k * key to calculate mask of. * * @return */ protected static int mask(AbstractKey k) { KeyInfo i = k.info(); switch (i.getAlgorythm()) { case RSAPublic: case RSAPrivate: if (((PublicKey) k).getPublicExponent() == 0x10001) { int l = i.getKeyLength(); if (l == 2048 / 8) return 0x01; if (l == 4096 / 8) return 0x02; } break; } throw new IllegalArgumentException("key can't be masked for address: " + i); }
keys.forEach(k -> { KeyInfo i = k.info(); report("\t✔︎ " + i.getAlgorythm() + ":" + i.getKeyLength() * 8 + ":" + i.getBase64Tag()); }); report("\nWhich can play roles:\n");
@Test public void symmetricKeyMustHaveRightInfo() { SymmetricKey k = new SymmetricKey(); KeyInfo h = k.info(); assertEquals(KeyInfo.Algorythm.AES256, h.getAlgorythm()); assertEquals(32, h.getKeyLength()); assertEquals(KeyInfo.PRF.None, h.getPRF()); }
@Test public void packKdf() throws Exception { KeyInfo h1 = new KeyInfo(KeyInfo.PRF.HMAC_SHA256, 4096, null, null); KeyInfo h2 = new KeyInfo(h1.pack()); assertEquals(h1.getAlgorythm(), h2.getAlgorythm()); assertEquals(h1.getPRF(), h2.getPRF()); assertEquals(h1.getRounds(), h2.getRounds()); assertEquals(h1.getKeyLength(), h2.getKeyLength()); assertEquals(KeyInfo.PRF.HMAC_SHA256, h2.getPRF()); assertEquals(KeyInfo.Algorythm.AES256, h2.getAlgorythm()); assertArrayEquals(h1.getTag(), h2.getTag()); }
assertEquals(h1.getPRF(), h2.getPRF()); assertEquals(h1.getRounds(), h2.getRounds()); assertEquals(h1.getKeyLength(), h2.getKeyLength()); assertEquals(512, h2.getKeyLength()); assertEquals(h1.getPRF(), h2.getPRF()); assertEquals(h1.getRounds(), h2.getRounds()); assertEquals(h1.getKeyLength(), h2.getKeyLength()); assertEquals(256, h2.getKeyLength()); assertEquals(h1.getPRF(), h2.getPRF()); assertEquals(h1.getRounds(), h2.getRounds()); assertEquals(h1.getKeyLength(), h2.getKeyLength()); assertEquals(32, h2.getKeyLength());