/// <summary> /// Encrypt dataToEncrypt using the specified encodingParams (RSA only). /// </summary> /// <param name="plainText"></param> /// <param name="label"></param> /// <returns></returns> public byte[] EncryptOaep(byte[] plainText, byte[] label) { if (plainText == null) { plainText = new byte[0]; } if (label == null) { label = new byte[0]; } #if TSS_USE_BCRYPT var paddingInfo = new BCryptOaepPaddingInfo(OaepHash, label); byte[] cipherText = Key.Encrypt(plainText, paddingInfo); #elif false var rr = new RawRsa(RsaProvider.ExportParameters(false), RsaProvider.KeySize); byte[] cipherText = rr.OaepEncrypt(plainText, OaepHash, label); #else RSAParameters parms = RsaProvider.ExportParameters(false); var alg = new BCryptAlgorithm(Native.BCRYPT_RSA_ALGORITHM); var key = alg.LoadRSAKey(parms.Exponent, parms.Modulus); var paddingInfo = new BCryptOaepPaddingInfo(OaepHash, label); byte[] cipherText = key.Encrypt(plainText, paddingInfo); key.Destroy(); alg.Close(); #endif return(cipherText); }
/// <summary> /// Encrypt dataToEncrypt using the specified encodingParams (RSA only). /// </summary> /// <param name="dataToEncrypt"></param> /// <param name="label"></param> /// <returns></returns> public byte[] EncryptOaep(byte[] plainText, byte[] label) { if (plainText == null) { plainText = new byte[0]; } if (label == null) { label = new byte[0]; } var rr = new RawRsa(Key); byte[] cipherText = rr.OaepEncrypt(plainText, OaepHash, label);; return(cipherText); }