CryptoAlgorithmRSAES_PKCS1_v1_5Mac.cpp [plain text]
#include "config.h"
#include "CryptoAlgorithmRSAES_PKCS1_v1_5.h"
#if ENABLE(SUBTLE_CRYPTO)
#include "CommonCryptoUtilities.h"
#include "CryptoKeyRSA.h"
namespace WebCore {
static ExceptionOr<Vector<uint8_t>> encryptRSAES_PKCS1_v1_5(const PlatformRSAKey key, size_t keyLength, const Vector<uint8_t>& data)
{
Vector<uint8_t> cipherText(keyLength / 8); size_t cipherTextLength = cipherText.size();
if (CCRSACryptorEncrypt(key, ccPKCS1Padding, data.data(), data.size(), cipherText.data(), &cipherTextLength, 0, 0, kCCDigestNone))
return Exception { OperationError };
return WTFMove(cipherText);
}
static ExceptionOr<Vector<uint8_t>> decryptRSAES_PKCS1_v1_5(const PlatformRSAKey key, size_t keyLength, const Vector<uint8_t>& data)
{
Vector<uint8_t> plainText(keyLength / 8); size_t plainTextLength = plainText.size();
if (CCRSACryptorDecrypt(key, ccPKCS1Padding, data.data(), data.size(), plainText.data(), &plainTextLength, 0, 0, kCCDigestNone))
return Exception { OperationError };
plainText.resize(plainTextLength);
return WTFMove(plainText);
}
ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSAES_PKCS1_v1_5::platformEncrypt(const CryptoKeyRSA& key, const Vector<uint8_t>& plainText)
{
return encryptRSAES_PKCS1_v1_5(key.platformKey(), key.keySizeInBits(), plainText);
}
ExceptionOr<Vector<uint8_t>> CryptoAlgorithmRSAES_PKCS1_v1_5::platformDecrypt(const CryptoKeyRSA& key, const Vector<uint8_t>& cipherText)
{
return decryptRSAES_PKCS1_v1_5(key.platformKey(), key.keySizeInBits(), cipherText);
}
}
#endif // ENABLE(SUBTLE_CRYPTO)