Search in sources :

Example 1 with RSAKeyManager

use of co.krypt.krypton.crypto.RSAKeyManager in project krypton-android by kryptco.

the class KeyManagerInstrumentedTest method signTamperAndVerify_fails.

@Test
public void signTamperAndVerify_fails() throws Exception {
    final Context context = InstrumentationRegistry.getTargetContext();
    for (KeyType type : SUPPORTED_KEY_TYPES) {
        for (SSHKeyPairI key : new SSHKeyPairI[] { KeyManager.loadOrGenerateKeyPair(context, type, "test"), new RSAKeyManager(context).loadOrGenerateNoDigestKeyPair("testnodigest") }) {
            byte[] data = SecureRandom.getSeed(32);
            for (String digest : SUPPORTED_DIGESTS) {
                byte[] signature = key.signDigest(digest, data);
                signature[signature.length - 1] ^= 0x01;
                assertTrue(!key.verifyDigest(digest, signature, data));
            }
        }
    }
}
Also used : Context(android.content.Context) KeyType(co.krypt.krypton.crypto.KeyType) SSHKeyPairI(co.krypt.krypton.crypto.SSHKeyPairI) RSAKeyManager(co.krypt.krypton.crypto.RSAKeyManager) Test(org.junit.Test)

Example 2 with RSAKeyManager

use of co.krypt.krypton.crypto.RSAKeyManager in project krypton-android by kryptco.

the class KeyManagerInstrumentedTest method signAndVerify_succeed.

@Test
public void signAndVerify_succeed() throws Exception {
    final Context context = InstrumentationRegistry.getTargetContext();
    for (KeyType type : SUPPORTED_KEY_TYPES) {
        for (SSHKeyPairI key : new SSHKeyPairI[] { KeyManager.loadOrGenerateKeyPair(context, type, "test"), new RSAKeyManager(context).loadOrGenerateNoDigestKeyPair("testnodigest") }) {
            byte[] data = SecureRandom.getSeed(32);
            for (String digest : SUPPORTED_DIGESTS) {
                byte[] signature = key.signDigest(digest, data);
                assertTrue(key.verifyDigest(digest, signature, data));
            }
        }
    }
}
Also used : Context(android.content.Context) KeyType(co.krypt.krypton.crypto.KeyType) SSHKeyPairI(co.krypt.krypton.crypto.SSHKeyPairI) RSAKeyManager(co.krypt.krypton.crypto.RSAKeyManager) Test(org.junit.Test)

Aggregations

Context (android.content.Context)2 KeyType (co.krypt.krypton.crypto.KeyType)2 RSAKeyManager (co.krypt.krypton.crypto.RSAKeyManager)2 SSHKeyPairI (co.krypt.krypton.crypto.SSHKeyPairI)2 Test (org.junit.Test)2