S/MIME: check if private and public key match

This commit is contained in:
M66B
2024-06-30 22:42:37 +02:00
parent a0fa0b487c
commit 1989631d1e
2 changed files with 16 additions and 1 deletions

View File

@@ -21,7 +21,11 @@ package eu.faircode.email;
import android.content.Context;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.cert.X509Certificate;
import java.util.List;
import java.util.Objects;
import javax.mail.Address;
import javax.mail.internet.InternetAddress;
@@ -42,4 +46,13 @@ public class SmimeHelper {
return (all ? count == recipients.size() : count > 0);
}
static boolean match(PrivateKey privkey, X509Certificate cert) {
if (privkey == null || cert == null)
return false;
PublicKey pubkey = cert.getPublicKey();
if (pubkey == null)
return false;
return Objects.equals(privkey.getAlgorithm(), pubkey.getAlgorithm());
}
}