Search in sources :

Example 21 with PublicKey

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

PublicKey (com.github.dedis.popstellar.model.objects.security.PublicKey)21 MessageID (com.github.dedis.popstellar.model.objects.security.MessageID)8 Channel (com.github.dedis.popstellar.model.objects.Channel)6 Lao (com.github.dedis.popstellar.model.objects.Lao)6 LAORepository (com.github.dedis.popstellar.repository.LAORepository)6 Test (org.junit.Test)4 ElectInstance (com.github.dedis.popstellar.model.objects.ElectInstance)3 Base64DataUtils.generatePublicKey (com.github.dedis.popstellar.testutils.Base64DataUtils.generatePublicKey)3 ConsensusElectAccept (com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusElectAccept)2 CreateLao (com.github.dedis.popstellar.model.network.method.message.data.lao.CreateLao)2 StateLao (com.github.dedis.popstellar.model.network.method.message.data.lao.StateLao)2 UpdateLao (com.github.dedis.popstellar.model.network.method.message.data.lao.UpdateLao)2 Chirp (com.github.dedis.popstellar.model.objects.Chirp)2 KeyPair (com.github.dedis.popstellar.model.objects.security.KeyPair)2 InvalidMessageIdException (com.github.dedis.popstellar.utility.error.InvalidMessageIdException)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 DateUtils.getRelativeTimeSpanString (android.text.format.DateUtils.getRelativeTimeSpanString)1 ImageButton (android.widget.ImageButton)1