public override IMac CreateEngine(EngineUsage usage) { IMac mac = provider.CreateEngine(usage); if (key != null) { mac.Init(new KeyParameter(key.GetKeyBytes())); } return(mac); }
protected override byte[] GenerateWrappedKey(ISymmetricKey contentKey) { AsymmetricRsaPublicKey rsaKey = asymmetricPublicKey as AsymmetricRsaPublicKey; if (rsaKey != null) { IKeyWrapper <FipsRsa.OaepWrapParameters> wrapper = CryptoServicesRegistrar.CreateService(rsaKey, new Security.SecureRandom()).CreateKeyWrapper(FipsRsa.WrapOaep.WithDigest(FipsShs.Sha1)); byte[] encKey = wrapper.Wrap(contentKey.GetKeyBytes()).Collect(); return(encKey); } throw new InvalidOperationException("algorithm for public key not matched"); }
public PkixContentEncryptor(DerObjectIdentifier encAlgorithm, SecureRandom random) { key = keyGenerators[encAlgorithm](random); algId = Utils.GetEncryptionSchemeIdentifier(encAlgorithm, random); IParameters <Algorithm> cipherParams = Utils.GetCipherParameters(algId); if (Utils.IsBlockMode(cipherParams.Algorithm)) { cipherBuilder = new PkixBlockCipherBuilder(algId, Utils.CreateBlockEncryptorBuilder(encAlgorithm, key.GetKeyBytes(), cipherParams)); } else if (Utils.IsAeadMode(cipherParams.Algorithm)) { cipherBuilder = new PkixAeadCipherBuilder(algId, Utils.CreateAeadEncryptorBuilder(encAlgorithm, key.GetKeyBytes(), cipherParams)); } else { cipherBuilder = new PkixCipherBuilder(algId, Utils.CreateEncryptorBuilder(encAlgorithm, key.GetKeyBytes(), cipherParams)); } }