@Test public void testRsaDecrypt() throws Exception { OpenPgpCapabilities openPgpCapabilities = OpenPgpCapabilities.fromBytes( Hex.decode("6e81de4f10d27600012401020000060364311500005f520f0073000080000000000000000000007381b7c00af" + "00000ff04c000ff00ffc106010800001103c206010800001103c306010800001103c407007f7f7f03" + "0303c53c4ec5fee25c4e89654d58cad8492510a89d3c3d8468da7b24e15bfc624c6a792794f15b759" + "9915f703aab55ed25424d60b17026b7b06c6ad4b9be30a3c63c000000000000000000000000000000" + "000000000000000000000000000000000000000000000000000000000000000000000000000000000" + "000000000cd0c59cd0f2a59cd0af059cd0c95" )); when(securityTokenConnection.getOpenPgpCapabilities()).thenReturn(openPgpCapabilities); ResponseApdu dummyResponseApdu = ResponseApdu.fromBytes(Hex.decode("010203049000")); when(commandFactory.createDecipherCommand(any(byte[].class), eq(RSA_ENC_MODULUS))).thenReturn(dummyCommandApdu); when(securityTokenConnection.communicate(dummyCommandApdu)).thenReturn(dummyResponseApdu); byte[] response = useCase.verifyAndDecryptSessionKey(RSA_ENC_SESSIONKEY_MPI, null); assertArrayEquals(Hex.decode("01020304"), response); }
public byte[] verifyAndDecryptSessionKey(@NonNull byte[] encryptedSessionKeyMpi, CanonicalizedPublicKey publicKey) throws IOException { connection.verifyPinForOther(); KeyFormat kf = connection.getOpenPgpCapabilities().getEncryptKeyFormat(); switch (kf.keyFormatType()) { case RSAKeyFormatType: return decryptSessionKeyRsa(encryptedSessionKeyMpi); case ECKeyFormatType: return decryptSessionKeyEcdh(encryptedSessionKeyMpi, (ECKeyFormat) kf, publicKey); default: throw new CardException("Unknown encryption key type!"); } }
PsoDecryptTokenOp { public byte[] verifyAndDecryptSessionKey(@NonNull byte[] encryptedSessionKeyMpi, CanonicalizedPublicKey publicKey) throws IOException { connection.verifyPinForOther(); KeyFormat kf = connection.getOpenPgpCapabilities().getEncryptKeyFormat(); switch (kf.keyFormatType()) { case RSAKeyFormatType: return decryptSessionKeyRsa(encryptedSessionKeyMpi); case ECKeyFormatType: return decryptSessionKeyEcdh(encryptedSessionKeyMpi, (ECKeyFormat) kf, publicKey); default: throw new CardException("Unknown encryption key type!"); } } }
PsoDecryptTokenOp { public byte[] verifyAndDecryptSessionKey(@NonNull byte[] encryptedSessionKeyMpi, CanonicalizedPublicKey publicKey) throws IOException { connection.verifyPinForOther(); KeyFormat kf = connection.getOpenPgpCapabilities().getEncryptKeyFormat(); switch (kf.keyFormatType()) { case RSAKeyFormatType: return decryptSessionKeyRsa(encryptedSessionKeyMpi); case ECKeyFormatType: return decryptSessionKeyEcdh(encryptedSessionKeyMpi, (ECKeyFormat) kf, publicKey); default: throw new CardException("Unknown encryption key type!"); } } private  PsoDecryptTokenOp(SecurityTokenConnection connection,
            JcaKeyFingerprintCalculator jcaKeyFingerprintCalculator); }
PsoDecryptTokenOp { public byte[] verifyAndDecryptSessionKey(@NonNull byte[] encryptedSessionKeyMpi, CanonicalizedPublicKey publicKey) throws IOException { connection.verifyPinForOther(); KeyFormat kf = connection.getOpenPgpCapabilities().getEncryptKeyFormat(); switch (kf.keyFormatType()) { case RSAKeyFormatType: return decryptSessionKeyRsa(encryptedSessionKeyMpi); case ECKeyFormatType: return decryptSessionKeyEcdh(encryptedSessionKeyMpi, (ECKeyFormat) kf, publicKey); default: throw new CardException("Unknown encryption key type!"); } } private  PsoDecryptTokenOp(SecurityTokenConnection connection,
            JcaKeyFingerprintCalculator jcaKeyFingerprintCalculator); static PsoDecryptTokenOp create(SecurityTokenConnection connection); byte[] verifyAndDecryptSessionKey(@NonNull byte[] encryptedSessionKeyMpi, CanonicalizedPublicKey publicKey); @VisibleForTesting byte[] getRsaOperationPayload(byte[] encryptedSessionKeyMpi); }
PsoDecryptTokenOp { public byte[] verifyAndDecryptSessionKey(@NonNull byte[] encryptedSessionKeyMpi, CanonicalizedPublicKey publicKey) throws IOException { connection.verifyPinForOther(); KeyFormat kf = connection.getOpenPgpCapabilities().getEncryptKeyFormat(); switch (kf.keyFormatType()) { case RSAKeyFormatType: return decryptSessionKeyRsa(encryptedSessionKeyMpi); case ECKeyFormatType: return decryptSessionKeyEcdh(encryptedSessionKeyMpi, (ECKeyFormat) kf, publicKey); default: throw new CardException("Unknown encryption key type!"); } } private  PsoDecryptTokenOp(SecurityTokenConnection connection,
            JcaKeyFingerprintCalculator jcaKeyFingerprintCalculator); static PsoDecryptTokenOp create(SecurityTokenConnection connection); byte[] verifyAndDecryptSessionKey(@NonNull byte[] encryptedSessionKeyMpi, CanonicalizedPublicKey publicKey); @VisibleForTesting byte[] getRsaOperationPayload(byte[] encryptedSessionKeyMpi);  }