use of com.github.dedis.popstellar.model.objects.security.privatekey.ProtectedPrivateKey in project popstellar by dedis.
the class PrivateKeyTest method badKeyFailsAtConstruction.
@Test
public void badKeyFailsAtConstruction() throws GeneralSecurityException {
assertThrows(IllegalArgumentException.class, () -> new PlainPrivateKey(new byte[] { 0, 1, 2 }));
KeysetHandle keyset = mock(KeysetHandle.class);
when(keyset.getPrimitive(PublicKeySign.class)).thenThrow(new GeneralSecurityException());
assertThrows(IllegalArgumentException.class, () -> new ProtectedPrivateKey(keyset));
}
use of com.github.dedis.popstellar.model.objects.security.privatekey.ProtectedPrivateKey in project popstellar by dedis.
the class KeyManager method getKeyPair.
@VisibleForTesting
public KeyPair getKeyPair(KeysetHandle keysetHandle) throws GeneralSecurityException, IOException {
PrivateKey privateKey = new ProtectedPrivateKey(keysetHandle);
PublicKey publicKey = getPublicKey(keysetHandle);
return new KeyPair(privateKey, publicKey);
}
use of com.github.dedis.popstellar.model.objects.security.privatekey.ProtectedPrivateKey in project popstellar by dedis.
the class PrivateKeyTest method signGivesSameValueForBothKeyType.
@Test
public void signGivesSameValueForBothKeyType() throws GeneralSecurityException {
PrivateKey key1 = new PlainPrivateKey(VALID_PRIVATE_KEY);
KeysetHandle keyset = mock(KeysetHandle.class);
when(keyset.getPrimitive(PublicKeySign.class)).thenReturn(new Ed25519Sign(VALID_PRIVATE_KEY));
PrivateKey key2 = new ProtectedPrivateKey(keyset);
Signature sign1 = key1.sign(DATA);
Signature sign2 = key2.sign(DATA);
assertEquals(sign1, sign2);
}
Aggregations