Search in sources :

Example 1 with ProtectedPrivateKey

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));
}
Also used : KeysetHandle(com.google.crypto.tink.KeysetHandle) GeneralSecurityException(java.security.GeneralSecurityException) PlainPrivateKey(com.github.dedis.popstellar.model.objects.security.privatekey.PlainPrivateKey) ProtectedPrivateKey(com.github.dedis.popstellar.model.objects.security.privatekey.ProtectedPrivateKey) Test(org.junit.Test)

Example 2 with ProtectedPrivateKey

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);
}
Also used : KeyPair(com.github.dedis.popstellar.model.objects.security.KeyPair) PrivateKey(com.github.dedis.popstellar.model.objects.security.PrivateKey) ProtectedPrivateKey(com.github.dedis.popstellar.model.objects.security.privatekey.ProtectedPrivateKey) PublicKey(com.github.dedis.popstellar.model.objects.security.PublicKey) ProtectedPrivateKey(com.github.dedis.popstellar.model.objects.security.privatekey.ProtectedPrivateKey) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 3 with ProtectedPrivateKey

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);
}
Also used : KeysetHandle(com.google.crypto.tink.KeysetHandle) ProtectedPrivateKey(com.github.dedis.popstellar.model.objects.security.privatekey.ProtectedPrivateKey) PlainPrivateKey(com.github.dedis.popstellar.model.objects.security.privatekey.PlainPrivateKey) Ed25519Sign(com.google.crypto.tink.subtle.Ed25519Sign) PlainPrivateKey(com.github.dedis.popstellar.model.objects.security.privatekey.PlainPrivateKey) ProtectedPrivateKey(com.github.dedis.popstellar.model.objects.security.privatekey.ProtectedPrivateKey) Test(org.junit.Test)

Aggregations

ProtectedPrivateKey (com.github.dedis.popstellar.model.objects.security.privatekey.ProtectedPrivateKey)3 PlainPrivateKey (com.github.dedis.popstellar.model.objects.security.privatekey.PlainPrivateKey)2 KeysetHandle (com.google.crypto.tink.KeysetHandle)2 Test (org.junit.Test)2 VisibleForTesting (androidx.annotation.VisibleForTesting)1 KeyPair (com.github.dedis.popstellar.model.objects.security.KeyPair)1 PrivateKey (com.github.dedis.popstellar.model.objects.security.PrivateKey)1 PublicKey (com.github.dedis.popstellar.model.objects.security.PublicKey)1 Ed25519Sign (com.google.crypto.tink.subtle.Ed25519Sign)1 GeneralSecurityException (java.security.GeneralSecurityException)1