public override int Read( byte[] buffer, int offset, int count) { CryptoServicesRegistrar.ApprovedModeCheck(isApprovedModeOnly, "CipherStream"); if (inCipher == null) { return(stream.Read(buffer, offset, count)); } int num = 0; while (num < count) { if (mInBuf == null || mInPos >= mInBuf.Length) { if (!FillInBuf()) { break; } } int numToCopy = System.Math.Min(count - num, mInBuf.Length - mInPos); Array.Copy(mInBuf, mInPos, buffer, offset + num, numToCopy); mInPos += numToCopy; num += numToCopy; } return(num); }
public override void Flush() { CryptoServicesRegistrar.ApprovedModeCheck(isApprovedModeOnly, "CipherStream"); // Note: outCipher.DoFinal is only called during Close() stream.Flush(); }
public override void Write( byte[] buffer, int offset, int count) { CryptoServicesRegistrar.ApprovedModeCheck(isApprovedModeOnly, "CipherStream"); Debug.Assert(buffer != null); Debug.Assert(0 <= offset && offset <= buffer.Length); Debug.Assert(count >= 0); int end = offset + count; Debug.Assert(0 <= end && end <= buffer.Length); if (outCipher == null) { stream.Write(buffer, offset, count); return; } byte[] data = outCipher.ProcessBytes(buffer, offset, count); if (data != null) { stream.Write(data, 0, data.Length); } }
public override void Close() { CryptoServicesRegistrar.ApprovedModeCheck(isApprovedModeOnly, "DigestStream"); Platform.Dispose(stream); base.Close(); }
public override void SetLength( long length) { CryptoServicesRegistrar.ApprovedModeCheck(isApprovedModeOnly, "DigestStream"); stream.SetLength(length); }
public override long Seek( long offset, SeekOrigin origin) { CryptoServicesRegistrar.ApprovedModeCheck(isApprovedModeOnly, "DigestStream"); return(stream.Seek(offset, origin)); }
public IMacFactory <A> CreateMacFactory <A>(A algorithmDetails) where A : IAuthenticationParameters <A, Algorithm> { CryptoServicesRegistrar.ApprovedModeCheck(approvedOnlyMode, "Service"); ValidateKeyUse(keyAlg, keyBytes, algorithmDetails.Algorithm); return(((IMacFactoryProvider <A>)prov).CreateMacFactory(algorithmDetails)); }
public IKeyWrapper <A> CreateKeyWrapper <A>(A algorithmDetails) where A : ISymmetricWrapParameters <A, Algorithm> { CryptoServicesRegistrar.ApprovedModeCheck(approvedOnlyMode, "Service"); ValidateKeyUse(keyAlg, keyBytes, algorithmDetails.Algorithm); return(((IKeyWrapperProvider <A>)prov).CreateKeyWrapper(algorithmDetails)); }
public IAeadCipherBuilder <A> CreateAeadEncryptorBuilder <A>(A algorithmDetails) where A : IParameters <Algorithm> { CryptoServicesRegistrar.ApprovedModeCheck(approvedOnlyMode, "Service"); ValidateKeyUse(keyAlg, keyBytes, algorithmDetails.Algorithm); return(((IAeadEncryptorBuilderProvider <A>)prov).CreateAeadEncryptorBuilder(algorithmDetails)); }
protected override void Dispose(bool disposing) { if (disposing) { CryptoServicesRegistrar.ApprovedModeCheck(isApprovedModeOnly, "DigestStream"); Platform.Dispose(stream); } base.Dispose(disposing); }
public ICipherBuilder <A> CreateEncryptorBuilder <A>(A algorithmDetails) where A : IParameters <Algorithm> { CryptoServicesRegistrar.ApprovedModeCheck(false, "Service"); if (algorithmDetails is IParametersWithIV <IParameters <GeneralAlgorithm>, GeneralAlgorithm> ) { return(((IEncryptorBuilderProvider <A>)provWithIV).CreateEncryptorBuilder(algorithmDetails)); } return(((IEncryptorBuilderProvider <A>)prov).CreateEncryptorBuilder(algorithmDetails)); }
public IMacFactory <A> CreateMacFactory <A>(A algorithmDetails) where A : IAuthenticationParameters <A, Algorithm> { CryptoServicesRegistrar.ApprovedModeCheck(false, "Service"); if (algorithmDetails is IAuthenticationParametersWithIV <A, Algorithm> ) { return(((IMacFactoryProvider <A>)provWithIV).CreateMacFactory(algorithmDetails)); } return(((IMacFactoryProvider <A>)prov).CreateMacFactory(algorithmDetails)); }
public override void WriteByte( byte b) { CryptoServicesRegistrar.ApprovedModeCheck(isApprovedModeOnly, "DigestStream"); if (outDigest != null) { outDigest.Update(b); } stream.WriteByte(b); }
public override void Close() { CryptoServicesRegistrar.ApprovedModeCheck(isApprovedModeOnly, "CipherStream"); if (outCipher != null) { byte[] data = outCipher.DoFinal(); stream.Write(data, 0, data.Length); stream.Flush(); } Platform.Dispose(stream); base.Close(); }
public IKeyWrapper <A> CreateKeyWrapper <A>(A algorithmDetails) where A : IParameters <Algorithm> { Rsa.Pkcs1v15WrapParameters pkcsP = algorithmDetails as Rsa.Pkcs1v15WrapParameters; if (pkcsP != null) { CryptoServicesRegistrar.ApprovedModeCheck(false, "RSA"); General.Utils.ApprovedModeCheck("service", algorithmDetails.Algorithm); return((IKeyWrapper <A>) new Rsa.Pkcs1v15KeyWrapper(pkcsP, publicKey)); } return((IKeyWrapper <A>) new Fips.FipsRsa.RsaKeyWrapper(algorithmDetails as Fips.FipsRsa.OaepWrapParameters, publicKey)); }
public ICipherBuilder <A> CreateDecryptorBuilder <A>(A algorithmDetails) where A : IParameters <Algorithm> { CryptoServicesRegistrar.ApprovedModeCheck(approvedOnlyMode, "Service"); ValidateKeyUse(keyAlg, keyBytes, algorithmDetails.Algorithm, true); if (algorithmDetails is TripleDes.ParametersWithIV) { CryptoServicesRegistrar.GeneralModeCheck(approvedOnlyMode, algorithmDetails.Algorithm); return(((IDecryptorBuilderProvider <A>)genProvForIV).CreateDecryptorBuilder(algorithmDetails)); } return(((IDecryptorBuilderProvider <A>)prov).CreateDecryptorBuilder(algorithmDetails)); }
public ISignatureFactory <A> CreateSignatureFactory <A>(A algorithmDetails) where A : IParameters <Algorithm> { CryptoServicesRegistrar.ApprovedModeCheck(approvedOnlyMode, "RSA"); Fips.FipsRsa.PssSignatureParameters pssParams = algorithmDetails as Fips.FipsRsa.PssSignatureParameters; if (pssParams != null) { return((ISignatureFactory <A>) new SignatureFactory <Fips.FipsRsa.PssSignatureParameters>(pssParams, new Fips.FipsRsa.PssSignerProvider(pssParams, privateKey))); } Fips.FipsRsa.SignatureParameters sigParams = algorithmDetails as Fips.FipsRsa.SignatureParameters; return((ISignatureFactory <A>) new SignatureFactory <Fips.FipsRsa.SignatureParameters>(sigParams, new Fips.FipsRsa.SignerProvider(sigParams, privateKey))); }
public override int ReadByte() { CryptoServicesRegistrar.ApprovedModeCheck(isApprovedModeOnly, "DigestStream"); int b = stream.ReadByte(); if (inDigest != null) { if (b >= 0) { inDigest.Update((byte)b); } } return(b); }
public ISignatureFactory<A> CreateSignatureFactory<A>(A algorithmDetails) where A : IParameters<Algorithm> { CryptoServicesRegistrar.ApprovedModeCheck(approvedOnlyMode, "EC"); if (algorithmDetails is Fips.FipsEC.SignatureParameters) { return (ISignatureFactory<A>)new SignatureFactory<Fips.FipsEC.SignatureParameters>(algorithmDetails as Fips.FipsEC.SignatureParameters, new Fips.FipsEC.SignerProvider(algorithmDetails as Fips.FipsEC.SignatureParameters, privateKey)); } else { General.Utils.ApprovedModeCheck("service", algorithmDetails.Algorithm); return (ISignatureFactory<A>)new SignatureFactory<General.EC.SignatureParameters>(algorithmDetails as General.EC.SignatureParameters, new General.EC.SignerProvider(algorithmDetails as General.EC.SignatureParameters, privateKey)); } }
public override void Write( byte[] buffer, int offset, int count) { CryptoServicesRegistrar.ApprovedModeCheck(isApprovedModeOnly, "DigestStream"); if (outDigest != null) { if (count > 0) { outDigest.BlockUpdate(buffer, offset, count); } } stream.Write(buffer, offset, count); }
protected override void Dispose(bool disposing) { if (disposing) { CryptoServicesRegistrar.ApprovedModeCheck(isApprovedModeOnly, "CipherStream"); if (outCipher != null) { byte[] data = outCipher.DoFinal(); stream.Write(data, 0, data.Length); stream.Flush(); } Platform.Dispose(stream); } base.Dispose(disposing); }
public override void WriteByte( byte b) { CryptoServicesRegistrar.ApprovedModeCheck(isApprovedModeOnly, "CipherStream"); if (outCipher == null) { stream.WriteByte(b); return; } byte[] data = outCipher.ProcessByte(b); if (data != null) { stream.Write(data, 0, data.Length); } }
public override int Read( byte[] buffer, int offset, int count) { CryptoServicesRegistrar.ApprovedModeCheck(isApprovedModeOnly, "DigestStream"); int n = stream.Read(buffer, offset, count); if (inDigest != null) { if (n > 0) { inDigest.BlockUpdate(buffer, offset, n); } } return(n); }
public override int ReadByte() { CryptoServicesRegistrar.ApprovedModeCheck(isApprovedModeOnly, "CipherStream"); if (inCipher == null) { return(stream.ReadByte()); } if (mInBuf == null || mInPos >= mInBuf.Length) { if (!FillInBuf()) { return(-1); } } return(mInBuf[mInPos++]); }
public IBlockCipherBuilder <A> CreateBlockEncryptorBuilder <A>(A algorithmDetails) where A : IParameters <Algorithm> { CryptoServicesRegistrar.ApprovedModeCheck(approvedOnlyMode, "Service"); ValidateKeyUse(keyAlg, keyBytes, algorithmDetails.Algorithm); try { return(((IBlockEncryptorBuilderProvider <A>)prov).CreateBlockEncryptorBuilder(algorithmDetails)); } catch (InvalidCastException e) { if (!AlgorithmModeUtils.isBlockCipherMode(algorithmDetails.Algorithm)) { throw new NotSupportedException("cannot create a block encryptor from non-block mode", e); } throw e; } }
public IKeyWrapper <A> CreateKeyWrapper <A>(A algorithmDetails) where A : IParameters <Algorithm> { CryptoServicesRegistrar.ApprovedModeCheck(approvedOnlyMode, "DH"); General.Utils.ApprovedModeCheck("service", algorithmDetails.Algorithm); ElGamal.OaepWrapParameters oaepP = algorithmDetails as ElGamal.OaepWrapParameters; if (oaepP != null) { return((IKeyWrapper <A>) new ElGamal.OaepKeyWrapper(oaepP, publicKey)); } ElGamal.Pkcs1v15WrapParameters pkcsP = algorithmDetails as ElGamal.Pkcs1v15WrapParameters; if (pkcsP != null) { return((IKeyWrapper <A>) new ElGamal.Pkcs1v15KeyWrapper(pkcsP, publicKey)); } throw new ArgumentException("unknown algorithm parameters"); }
internal virtual IDigest WriteDigest() { CryptoServicesRegistrar.ApprovedModeCheck(isApprovedModeOnly, "DigestStream"); return(outDigest); }
public IAgreementCalculator<A> CreateAgreementCalculator<A>(A algorithmDetails) where A : IParameters<Algorithm> { CryptoServicesRegistrar.ApprovedModeCheck(approvedOnlyMode, "EC"); return (IAgreementCalculator<A>)new FipsEC.AgreementCalculator(algorithmDetails as FipsEC.AgreementParameters, privateKey); }
public override void Flush() { CryptoServicesRegistrar.ApprovedModeCheck(isApprovedModeOnly, "DigestStream"); stream.Flush(); }
internal virtual ISigner WriteSigner() { CryptoServicesRegistrar.ApprovedModeCheck(isApprovedModeOnly, "SignerStream"); return(outSigner); }