Search in sources :

Example 1 with Base64URLData

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

the class KeyManagerTest method keyPairIsRight.

@Test
public void keyPairIsRight() throws GeneralSecurityException {
    KeyManager keyManager = new KeyManager(androidKeysetManager, wallet);
    KeyPair mainKeyPair = keyManager.getMainKeyPair();
    PublicKey mainKey = keyManager.getMainPublicKey();
    assertEquals(mainKey, mainKeyPair.getPublicKey());
    // We cannot extract the public key from the keyset handle
    // But we can make sure both signatures are equals and the key manager keypair can verify it
    PublicKeySign signer = androidKeysetManager.getKeysetHandle().getPrimitive(PublicKeySign.class);
    // Generate any data, here a message id
    Base64URLData data = Base64DataUtils.generateMessageID();
    Signature signature = mainKeyPair.sign(data);
    assertArrayEquals(signer.sign(data.getData()), signature.getData());
    assertTrue(mainKey.verify(signature, data));
}
Also used : KeyPair(com.github.dedis.popstellar.model.objects.security.KeyPair) Base64URLData(com.github.dedis.popstellar.model.objects.security.Base64URLData) PublicKey(com.github.dedis.popstellar.model.objects.security.PublicKey) Signature(com.github.dedis.popstellar.model.objects.security.Signature) PublicKeySign(com.google.crypto.tink.PublicKeySign) Test(org.junit.Test) HiltAndroidTest(dagger.hilt.android.testing.HiltAndroidTest)

Aggregations

Base64URLData (com.github.dedis.popstellar.model.objects.security.Base64URLData)1 KeyPair (com.github.dedis.popstellar.model.objects.security.KeyPair)1 PublicKey (com.github.dedis.popstellar.model.objects.security.PublicKey)1 Signature (com.github.dedis.popstellar.model.objects.security.Signature)1 PublicKeySign (com.google.crypto.tink.PublicKeySign)1 HiltAndroidTest (dagger.hilt.android.testing.HiltAndroidTest)1 Test (org.junit.Test)1