Search in sources :

Example 1 with PlainPrivateKey

use of com.github.dedis.popstellar.model.objects.security.privatekey.PlainPrivateKey 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 PlainPrivateKey

use of com.github.dedis.popstellar.model.objects.security.privatekey.PlainPrivateKey in project popstellar by dedis.

the class PrivateKeyTest method signGivesExpectedValue.

@Test
public void signGivesExpectedValue() throws GeneralSecurityException {
    PrivateKey key = new PlainPrivateKey(VALID_PRIVATE_KEY);
    Signature sign = key.sign(DATA);
    assertEquals(EXPECTED_SIGNATURE, sign);
}
Also used : ProtectedPrivateKey(com.github.dedis.popstellar.model.objects.security.privatekey.ProtectedPrivateKey) PlainPrivateKey(com.github.dedis.popstellar.model.objects.security.privatekey.PlainPrivateKey) PlainPrivateKey(com.github.dedis.popstellar.model.objects.security.privatekey.PlainPrivateKey) Test(org.junit.Test)

Example 3 with PlainPrivateKey

use of com.github.dedis.popstellar.model.objects.security.privatekey.PlainPrivateKey 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)

Example 4 with PlainPrivateKey

use of com.github.dedis.popstellar.model.objects.security.privatekey.PlainPrivateKey in project popstellar by dedis.

the class PrivateKeyTest method privateKeyHidesValueInStringRepresentation.

@Test
public void privateKeyHidesValueInStringRepresentation() {
    PlainPrivateKey key = new PlainPrivateKey(VALID_PRIVATE_KEY);
    assertFalse(key.toString().contains(key.getEncoded()));
}
Also used : PlainPrivateKey(com.github.dedis.popstellar.model.objects.security.privatekey.PlainPrivateKey) Test(org.junit.Test)

Aggregations

PlainPrivateKey (com.github.dedis.popstellar.model.objects.security.privatekey.PlainPrivateKey)4 Test (org.junit.Test)4 ProtectedPrivateKey (com.github.dedis.popstellar.model.objects.security.privatekey.ProtectedPrivateKey)3 KeysetHandle (com.google.crypto.tink.KeysetHandle)2 Ed25519Sign (com.google.crypto.tink.subtle.Ed25519Sign)1 GeneralSecurityException (java.security.GeneralSecurityException)1