This commit is contained in:
2026-06-15 18:18:16 +08:00
parent 97c9fba14e
commit 2b9f134e5f
4164 changed files with 386922 additions and 79 deletions

View File

@@ -0,0 +1,97 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.IO;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Cms;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.IO;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Utilities;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Security;
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Operators
{
public class Asn1CipherBuilderWithKey : ICipherBuilderWithKey
{
private readonly KeyParameter encKey;
private AlgorithmIdentifier algorithmIdentifier;
public Asn1CipherBuilderWithKey(DerObjectIdentifier encryptionOID, int keySize, SecureRandom random)
{
random = CryptoServicesRegistrar.GetSecureRandom(random);
CipherKeyGenerator keyGen = CipherKeyGeneratorFactory.CreateKeyGenerator(encryptionOID, random);
encKey = new KeyParameter(keyGen.GenerateKey());
algorithmIdentifier = AlgorithmIdentifierFactory.GenerateEncryptionAlgID(encryptionOID, encKey.GetKey().Length * 8, random);
}
public object AlgorithmDetails
{
get { return algorithmIdentifier; }
}
public int GetMaxOutputSize(int inputLen)
{
throw new NotImplementedException();
}
public ICipher BuildCipher(Stream stream)
{
object cipher = EnvelopedDataHelper.CreateContentCipher(true, encKey, algorithmIdentifier);
//
// BufferedBlockCipher
// IStreamCipher
//
if (cipher is IStreamCipher)
{
cipher = new BufferedStreamCipher((IStreamCipher)cipher);
}
if (stream == null)
{
stream = new MemoryStream();
}
return new BufferedCipherWrapper((IBufferedCipher)cipher, stream);
}
public ICipherParameters Key
{
get { return encKey; }
}
}
public class BufferedCipherWrapper : ICipher
{
private readonly IBufferedCipher bufferedCipher;
private readonly CipherStream stream;
public BufferedCipherWrapper(IBufferedCipher bufferedCipher, Stream source)
{
this.bufferedCipher = bufferedCipher;
stream = new CipherStream(source, bufferedCipher, bufferedCipher);
}
public int GetMaxOutputSize(int inputLen)
{
return bufferedCipher.GetOutputSize(inputLen);
}
public int GetUpdateOutputSize(int inputLen)
{
return bufferedCipher.GetUpdateOutputSize(inputLen);
}
public Stream Stream
{
get { return stream; }
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d89fe368529c9b6458fae30b91d4c33f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,76 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.IO;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.IO;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Security;
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Operators
{
public class Asn1DigestFactory
: IDigestFactory
{
public static Asn1DigestFactory Get(DerObjectIdentifier oid)
{
return new Asn1DigestFactory(DigestUtilities.GetDigest(oid), oid);
}
public static Asn1DigestFactory Get(string mechanism)
{
DerObjectIdentifier oid = DigestUtilities.GetObjectIdentifier(mechanism);
return new Asn1DigestFactory(DigestUtilities.GetDigest(oid), oid);
}
private readonly IDigest mDigest;
private readonly DerObjectIdentifier mOid;
public Asn1DigestFactory(IDigest digest, DerObjectIdentifier oid)
{
this.mDigest = digest;
this.mOid = oid;
}
public virtual object AlgorithmDetails
{
get { return new AlgorithmIdentifier(mOid); }
}
public virtual int DigestLength
{
get { return mDigest.GetDigestSize(); }
}
public virtual IStreamCalculator<IBlockResult> CreateCalculator()
{
return new DfDigestStream(mDigest);
}
}
internal class DfDigestStream
: IStreamCalculator<SimpleBlockResult>
{
private readonly DigestSink mStream;
public DfDigestStream(IDigest digest)
{
this.mStream = new DigestSink(digest);
}
public Stream Stream
{
get { return mStream; }
}
public SimpleBlockResult GetResult()
{
byte[] result = new byte[mStream.Digest.GetDigestSize()];
mStream.Digest.DoFinal(result, 0);
return new SimpleBlockResult(result);
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d3925190f0b3cdb4485785fb81e2ada9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,318 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.Collections.Generic;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Nist;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Oiw;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Pkcs;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Encodings;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Engines;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Security;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.X509;
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Operators
{
public class Asn1KeyWrapper
: IKeyWrapper
{
private string algorithm;
private IKeyWrapper wrapper;
public Asn1KeyWrapper(string algorithm, X509Certificate cert)
{
this.algorithm = algorithm;
wrapper = KeyWrapperUtil.WrapperForName(algorithm, cert.GetPublicKey());
}
public Asn1KeyWrapper(DerObjectIdentifier algorithm, X509Certificate cert)
: this(algorithm, cert.GetPublicKey())
{
}
public Asn1KeyWrapper(DerObjectIdentifier algorithm, ICipherParameters key)
: this(algorithm, null, key)
{
}
public Asn1KeyWrapper(DerObjectIdentifier algorithm, Asn1Encodable parameters, X509Certificate cert)
:this(algorithm, parameters, cert.GetPublicKey())
{
}
public Asn1KeyWrapper(DerObjectIdentifier algorithm, Asn1Encodable parameters, ICipherParameters key)
{
this.algorithm = algorithm.Id;
if (algorithm.Equals(PkcsObjectIdentifiers.IdRsaesOaep))
{
RsaesOaepParameters oaepParams = RsaesOaepParameters.GetInstance(parameters);
WrapperProvider provider;
if (oaepParams.MaskGenAlgorithm.Algorithm.Equals(PkcsObjectIdentifiers.IdMgf1))
{
AlgorithmIdentifier digAlg = AlgorithmIdentifier.GetInstance(oaepParams.MaskGenAlgorithm.Parameters);
provider = new RsaOaepWrapperProvider(oaepParams.HashAlgorithm.Algorithm, digAlg.Algorithm);
}
else
{
provider = new RsaOaepWrapperProvider(oaepParams.HashAlgorithm.Algorithm, oaepParams.MaskGenAlgorithm.Algorithm);
}
wrapper = (IKeyWrapper)provider.CreateWrapper(true, key);
}
else if (algorithm.Equals(PkcsObjectIdentifiers.RsaEncryption))
{
wrapper = (IKeyWrapper)new RsaPkcs1Wrapper(true, key);
}
else
{
throw new ArgumentException("unknown algorithm: " + algorithm.Id);
}
}
public object AlgorithmDetails
{
get { return wrapper.AlgorithmDetails; }
}
public IBlockResult Wrap(byte[] keyData)
{
return wrapper.Wrap(keyData);
}
}
public class Asn1KeyUnwrapper
: IKeyUnwrapper
{
private string algorithm;
private IKeyUnwrapper wrapper;
public Asn1KeyUnwrapper(string algorithm, ICipherParameters key)
{
this.algorithm = algorithm;
wrapper = KeyWrapperUtil.UnwrapperForName(algorithm, key);
}
public Asn1KeyUnwrapper(DerObjectIdentifier algorithm, ICipherParameters key)
: this(algorithm, null, key)
{
}
public Asn1KeyUnwrapper(DerObjectIdentifier algorithm, Asn1Encodable parameters, ICipherParameters key)
{
this.algorithm = algorithm.Id;
if (algorithm.Equals(PkcsObjectIdentifiers.IdRsaesOaep))
{
RsaesOaepParameters oaepParams = RsaesOaepParameters.GetInstance(parameters);
WrapperProvider provider;
if (oaepParams.MaskGenAlgorithm.Algorithm.Equals(PkcsObjectIdentifiers.IdMgf1))
{
AlgorithmIdentifier digAlg = AlgorithmIdentifier.GetInstance(oaepParams.MaskGenAlgorithm.Parameters);
provider = new RsaOaepWrapperProvider(oaepParams.HashAlgorithm.Algorithm, digAlg.Algorithm);
}
else
{
provider = new RsaOaepWrapperProvider(oaepParams.HashAlgorithm.Algorithm, oaepParams.MaskGenAlgorithm.Algorithm);
}
wrapper = (IKeyUnwrapper)provider.CreateWrapper(false, key);
}
else if (algorithm.Equals(PkcsObjectIdentifiers.RsaEncryption))
{
RsaesOaepParameters oaepParams = RsaesOaepParameters.GetInstance(parameters);
WrapperProvider provider;
if (oaepParams.MaskGenAlgorithm.Algorithm.Equals(PkcsObjectIdentifiers.IdMgf1))
{
AlgorithmIdentifier digAlg = AlgorithmIdentifier.GetInstance(oaepParams.MaskGenAlgorithm.Parameters);
provider = new RsaOaepWrapperProvider(oaepParams.HashAlgorithm.Algorithm, digAlg.Algorithm);
}
else
{
provider = new RsaOaepWrapperProvider(oaepParams.HashAlgorithm.Algorithm, oaepParams.MaskGenAlgorithm.Algorithm);
}
wrapper = (IKeyUnwrapper)new RsaPkcs1Wrapper(false, key);
}
else
{
throw new ArgumentException("unknown algorithm: " + algorithm.Id);
}
}
public object AlgorithmDetails
{
get { return wrapper.AlgorithmDetails; }
}
public IBlockResult Unwrap(byte[] keyData, int offSet, int length)
{
return wrapper.Unwrap(keyData, offSet, length);
}
}
internal class KeyWrapperUtil
{
//
// Provider
//
private static readonly Dictionary<string, WrapperProvider> m_providerMap =
new Dictionary<string, WrapperProvider>(StringComparer.OrdinalIgnoreCase);
static KeyWrapperUtil()
{
m_providerMap.Add("RSA/ECB/PKCS1PADDING", new RsaOaepWrapperProvider(OiwObjectIdentifiers.IdSha1));
m_providerMap.Add("RSA/NONE/PKCS1PADDING", new RsaOaepWrapperProvider(OiwObjectIdentifiers.IdSha1));
m_providerMap.Add("RSA/NONE/OAEPWITHSHA1ANDMGF1PADDING", new RsaOaepWrapperProvider(OiwObjectIdentifiers.IdSha1));
m_providerMap.Add("RSA/NONE/OAEPWITHSHA224ANDMGF1PADDING", new RsaOaepWrapperProvider(NistObjectIdentifiers.IdSha224));
m_providerMap.Add("RSA/NONE/OAEPWITHSHA256ANDMGF1PADDING", new RsaOaepWrapperProvider(NistObjectIdentifiers.IdSha256));
m_providerMap.Add("RSA/NONE/OAEPWITHSHA384ANDMGF1PADDING", new RsaOaepWrapperProvider(NistObjectIdentifiers.IdSha384));
m_providerMap.Add("RSA/NONE/OAEPWITHSHA512ANDMGF1PADDING", new RsaOaepWrapperProvider(NistObjectIdentifiers.IdSha512));
m_providerMap.Add("RSA/NONE/OAEPWITHSHA256ANDMGF1WITHSHA1PADDING", new RsaOaepWrapperProvider(NistObjectIdentifiers.IdSha256, OiwObjectIdentifiers.IdSha1));
}
public static IKeyWrapper WrapperForName(string algorithm, ICipherParameters parameters)
{
if (!m_providerMap.TryGetValue(algorithm, out var provider))
throw new ArgumentException("could not resolve " + algorithm + " to a KeyWrapper");
return (IKeyWrapper)provider.CreateWrapper(true, parameters);
}
public static IKeyUnwrapper UnwrapperForName(string algorithm, ICipherParameters parameters)
{
if (!m_providerMap.TryGetValue(algorithm, out var provider))
throw new ArgumentException("could not resolve " + algorithm + " to a KeyUnwrapper");
return (IKeyUnwrapper)provider.CreateWrapper(false, parameters);
}
}
internal interface WrapperProvider
{
object CreateWrapper(bool forWrapping, ICipherParameters parameters);
}
internal class RsaPkcs1Wrapper : IKeyWrapper, IKeyUnwrapper
{
private readonly AlgorithmIdentifier algId;
private readonly IAsymmetricBlockCipher engine;
public RsaPkcs1Wrapper(bool forWrapping, ICipherParameters parameters)
{
this.algId = new AlgorithmIdentifier(
PkcsObjectIdentifiers.RsaEncryption,
DerNull.Instance);
this.engine = new Pkcs1Encoding(new RsaBlindedEngine());
this.engine.Init(forWrapping, parameters);
}
public object AlgorithmDetails
{
get { return algId; }
}
public IBlockResult Unwrap(byte[] cipherText, int offset, int length)
{
return new SimpleBlockResult(engine.ProcessBlock(cipherText, offset, length));
}
public IBlockResult Wrap(byte[] keyData)
{
return new SimpleBlockResult(engine.ProcessBlock(keyData, 0, keyData.Length));
}
}
internal class RsaPkcs1WrapperProvider
: WrapperProvider
{
internal RsaPkcs1WrapperProvider()
{
}
object WrapperProvider.CreateWrapper(bool forWrapping, ICipherParameters parameters)
{
return new RsaPkcs1Wrapper(forWrapping, parameters);
}
}
internal class RsaOaepWrapper : IKeyWrapper, IKeyUnwrapper
{
private readonly AlgorithmIdentifier algId;
private readonly IAsymmetricBlockCipher engine;
public RsaOaepWrapper(bool forWrapping, ICipherParameters parameters, DerObjectIdentifier digestOid)
: this(forWrapping, parameters, digestOid, digestOid)
{
}
public RsaOaepWrapper(bool forWrapping, ICipherParameters parameters, DerObjectIdentifier digestOid, DerObjectIdentifier mgfOid)
{
AlgorithmIdentifier digestAlgId = new AlgorithmIdentifier(digestOid, DerNull.Instance);
if (mgfOid.Equals(NistObjectIdentifiers.IdShake128) || mgfOid.Equals(NistObjectIdentifiers.IdShake256))
{
this.algId = new AlgorithmIdentifier(
PkcsObjectIdentifiers.IdRsaesOaep,
new RsaesOaepParameters(
digestAlgId,
new AlgorithmIdentifier(mgfOid),
RsaesOaepParameters.DefaultPSourceAlgorithm));
}
else
{
this.algId = new AlgorithmIdentifier(
PkcsObjectIdentifiers.IdRsaesOaep,
new RsaesOaepParameters(
digestAlgId,
new AlgorithmIdentifier(PkcsObjectIdentifiers.IdMgf1, new AlgorithmIdentifier(mgfOid, DerNull.Instance)),
RsaesOaepParameters.DefaultPSourceAlgorithm));
}
this.engine = new OaepEncoding(new RsaBlindedEngine(), DigestUtilities.GetDigest(digestOid), DigestUtilities.GetDigest(mgfOid), null);
this.engine.Init(forWrapping, parameters);
}
public object AlgorithmDetails
{
get { return algId; }
}
public IBlockResult Unwrap(byte[] cipherText, int offset, int length)
{
return new SimpleBlockResult(engine.ProcessBlock(cipherText, offset, length));
}
public IBlockResult Wrap(byte[] keyData)
{
return new SimpleBlockResult(engine.ProcessBlock(keyData, 0, keyData.Length));
}
}
internal class RsaOaepWrapperProvider
: WrapperProvider
{
private readonly DerObjectIdentifier digestOid;
private readonly DerObjectIdentifier mgfOid;
internal RsaOaepWrapperProvider(DerObjectIdentifier digestOid)
{
this.digestOid = digestOid;
this.mgfOid = digestOid;
}
internal RsaOaepWrapperProvider(DerObjectIdentifier digestOid, DerObjectIdentifier mgfOid)
{
this.digestOid = digestOid;
this.mgfOid = mgfOid;
}
object WrapperProvider.CreateWrapper(bool forWrapping, ICipherParameters parameters)
{
return new RsaOaepWrapper(forWrapping, parameters, digestOid, mgfOid);
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 79910083773a90945ae630475a9fc516
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,421 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.Collections.Generic;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.CryptoPro;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Nist;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Oiw;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Pkcs;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Rosstandart;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.TeleTrust;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.X9;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Security;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections;
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Operators
{
internal class X509Utilities
{
private static readonly IDictionary<string, DerObjectIdentifier> m_algorithms =
new Dictionary<string, DerObjectIdentifier>(StringComparer.OrdinalIgnoreCase);
private static readonly IDictionary<string, Asn1Encodable> m_exParams =
new Dictionary<string, Asn1Encodable>(StringComparer.OrdinalIgnoreCase);
private static readonly HashSet<DerObjectIdentifier> noParams = new HashSet<DerObjectIdentifier>();
static X509Utilities()
{
m_algorithms.Add("MD2WITHRSAENCRYPTION", PkcsObjectIdentifiers.MD2WithRsaEncryption);
m_algorithms.Add("MD2WITHRSA", PkcsObjectIdentifiers.MD2WithRsaEncryption);
m_algorithms.Add("MD5WITHRSAENCRYPTION", PkcsObjectIdentifiers.MD5WithRsaEncryption);
m_algorithms.Add("MD5WITHRSA", PkcsObjectIdentifiers.MD5WithRsaEncryption);
m_algorithms.Add("SHA1WITHRSAENCRYPTION", PkcsObjectIdentifiers.Sha1WithRsaEncryption);
m_algorithms.Add("SHA-1WITHRSAENCRYPTION", PkcsObjectIdentifiers.Sha1WithRsaEncryption);
m_algorithms.Add("SHA1WITHRSA", PkcsObjectIdentifiers.Sha1WithRsaEncryption);
m_algorithms.Add("SHA-1WITHRSA", PkcsObjectIdentifiers.Sha1WithRsaEncryption);
m_algorithms.Add("SHA224WITHRSAENCRYPTION", PkcsObjectIdentifiers.Sha224WithRsaEncryption);
m_algorithms.Add("SHA-224WITHRSAENCRYPTION", PkcsObjectIdentifiers.Sha224WithRsaEncryption);
m_algorithms.Add("SHA224WITHRSA", PkcsObjectIdentifiers.Sha224WithRsaEncryption);
m_algorithms.Add("SHA-224WITHRSA", PkcsObjectIdentifiers.Sha224WithRsaEncryption);
m_algorithms.Add("SHA256WITHRSAENCRYPTION", PkcsObjectIdentifiers.Sha256WithRsaEncryption);
m_algorithms.Add("SHA-256WITHRSAENCRYPTION", PkcsObjectIdentifiers.Sha256WithRsaEncryption);
m_algorithms.Add("SHA256WITHRSA", PkcsObjectIdentifiers.Sha256WithRsaEncryption);
m_algorithms.Add("SHA-256WITHRSA", PkcsObjectIdentifiers.Sha256WithRsaEncryption);
m_algorithms.Add("SHA384WITHRSAENCRYPTION", PkcsObjectIdentifiers.Sha384WithRsaEncryption);
m_algorithms.Add("SHA-384WITHRSAENCRYPTION", PkcsObjectIdentifiers.Sha384WithRsaEncryption);
m_algorithms.Add("SHA384WITHRSA", PkcsObjectIdentifiers.Sha384WithRsaEncryption);
m_algorithms.Add("SHA-384WITHRSA", PkcsObjectIdentifiers.Sha384WithRsaEncryption);
m_algorithms.Add("SHA512WITHRSAENCRYPTION", PkcsObjectIdentifiers.Sha512WithRsaEncryption);
m_algorithms.Add("SHA-512WITHRSAENCRYPTION", PkcsObjectIdentifiers.Sha512WithRsaEncryption);
m_algorithms.Add("SHA512WITHRSA", PkcsObjectIdentifiers.Sha512WithRsaEncryption);
m_algorithms.Add("SHA-512WITHRSA", PkcsObjectIdentifiers.Sha512WithRsaEncryption);
m_algorithms.Add("SHA512(224)WITHRSAENCRYPTION", PkcsObjectIdentifiers.Sha512_224WithRSAEncryption);
m_algorithms.Add("SHA-512(224)WITHRSAENCRYPTION", PkcsObjectIdentifiers.Sha512_224WithRSAEncryption);
m_algorithms.Add("SHA512(224)WITHRSA", PkcsObjectIdentifiers.Sha512_224WithRSAEncryption);
m_algorithms.Add("SHA-512(224)WITHRSA", PkcsObjectIdentifiers.Sha512_224WithRSAEncryption);
m_algorithms.Add("SHA512(256)WITHRSAENCRYPTION", PkcsObjectIdentifiers.Sha512_256WithRSAEncryption);
m_algorithms.Add("SHA-512(256)WITHRSAENCRYPTION", PkcsObjectIdentifiers.Sha512_256WithRSAEncryption);
m_algorithms.Add("SHA512(256)WITHRSA", PkcsObjectIdentifiers.Sha512_256WithRSAEncryption);
m_algorithms.Add("SHA-512(256)WITHRSA", PkcsObjectIdentifiers.Sha512_256WithRSAEncryption);
m_algorithms.Add("SHA3-224WITHRSAENCRYPTION", NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_224);
m_algorithms.Add("SHA3-256WITHRSAENCRYPTION", NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_256);
m_algorithms.Add("SHA3-384WITHRSAENCRYPTION", NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_384);
m_algorithms.Add("SHA3-512WITHRSAENCRYPTION", NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_512);
m_algorithms.Add("SHA3-224WITHRSA", NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_224);
m_algorithms.Add("SHA3-256WITHRSA", NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_256);
m_algorithms.Add("SHA3-384WITHRSA", NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_384);
m_algorithms.Add("SHA3-512WITHRSA", NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_512);
m_algorithms.Add("SHA1WITHRSAANDMGF1", PkcsObjectIdentifiers.IdRsassaPss);
m_algorithms.Add("SHA224WITHRSAANDMGF1", PkcsObjectIdentifiers.IdRsassaPss);
m_algorithms.Add("SHA256WITHRSAANDMGF1", PkcsObjectIdentifiers.IdRsassaPss);
m_algorithms.Add("SHA384WITHRSAANDMGF1", PkcsObjectIdentifiers.IdRsassaPss);
m_algorithms.Add("SHA512WITHRSAANDMGF1", PkcsObjectIdentifiers.IdRsassaPss);
m_algorithms.Add("RIPEMD160WITHRSAENCRYPTION", TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD160);
m_algorithms.Add("RIPEMD160WITHRSA", TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD160);
m_algorithms.Add("RIPEMD128WITHRSAENCRYPTION", TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD128);
m_algorithms.Add("RIPEMD128WITHRSA", TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD128);
m_algorithms.Add("RIPEMD256WITHRSAENCRYPTION", TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD256);
m_algorithms.Add("RIPEMD256WITHRSA", TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD256);
m_algorithms.Add("SHA1WITHDSA", X9ObjectIdentifiers.IdDsaWithSha1);
m_algorithms.Add("DSAWITHSHA1", X9ObjectIdentifiers.IdDsaWithSha1);
m_algorithms.Add("SHA224WITHDSA", NistObjectIdentifiers.DsaWithSha224);
m_algorithms.Add("SHA256WITHDSA", NistObjectIdentifiers.DsaWithSha256);
m_algorithms.Add("SHA384WITHDSA", NistObjectIdentifiers.DsaWithSha384);
m_algorithms.Add("SHA512WITHDSA", NistObjectIdentifiers.DsaWithSha512);
m_algorithms.Add("SHA1WITHECDSA", X9ObjectIdentifiers.ECDsaWithSha1);
m_algorithms.Add("ECDSAWITHSHA1", X9ObjectIdentifiers.ECDsaWithSha1);
m_algorithms.Add("SHA224WITHECDSA", X9ObjectIdentifiers.ECDsaWithSha224);
m_algorithms.Add("SHA256WITHECDSA", X9ObjectIdentifiers.ECDsaWithSha256);
m_algorithms.Add("SHA384WITHECDSA", X9ObjectIdentifiers.ECDsaWithSha384);
m_algorithms.Add("SHA512WITHECDSA", X9ObjectIdentifiers.ECDsaWithSha512);
m_algorithms.Add("GOST3411WITHGOST3410", CryptoProObjectIdentifiers.GostR3411x94WithGostR3410x94);
m_algorithms.Add("GOST3411WITHGOST3410-94", CryptoProObjectIdentifiers.GostR3411x94WithGostR3410x94);
m_algorithms.Add("GOST3411WITHECGOST3410", CryptoProObjectIdentifiers.GostR3411x94WithGostR3410x2001);
m_algorithms.Add("GOST3411WITHECGOST3410-2001", CryptoProObjectIdentifiers.GostR3411x94WithGostR3410x2001);
m_algorithms.Add("GOST3411WITHGOST3410-2001", CryptoProObjectIdentifiers.GostR3411x94WithGostR3410x2001);
m_algorithms.Add("GOST3411-2012-256WITHECGOST3410", RosstandartObjectIdentifiers.id_tc26_signwithdigest_gost_3410_12_256);
m_algorithms.Add("GOST3411-2012-256WITHECGOST3410-2012-256", RosstandartObjectIdentifiers.id_tc26_signwithdigest_gost_3410_12_256);
m_algorithms.Add("GOST3411-2012-512WITHECGOST3410", RosstandartObjectIdentifiers.id_tc26_signwithdigest_gost_3410_12_512);
m_algorithms.Add("GOST3411-2012-512WITHECGOST3410-2012-512", RosstandartObjectIdentifiers.id_tc26_signwithdigest_gost_3410_12_512);
//
// According to RFC 3279, the ASN.1 encoding SHALL (id-dsa-with-sha1) or MUST (ecdsa-with-SHA*) omit the parameters field.
// The parameters field SHALL be NULL for RSA based signature algorithms.
//
noParams.Add(X9ObjectIdentifiers.ECDsaWithSha1);
noParams.Add(X9ObjectIdentifiers.ECDsaWithSha224);
noParams.Add(X9ObjectIdentifiers.ECDsaWithSha256);
noParams.Add(X9ObjectIdentifiers.ECDsaWithSha384);
noParams.Add(X9ObjectIdentifiers.ECDsaWithSha512);
noParams.Add(X9ObjectIdentifiers.IdDsaWithSha1);
noParams.Add(OiwObjectIdentifiers.DsaWithSha1);
noParams.Add(NistObjectIdentifiers.DsaWithSha224);
noParams.Add(NistObjectIdentifiers.DsaWithSha256);
noParams.Add(NistObjectIdentifiers.DsaWithSha384);
noParams.Add(NistObjectIdentifiers.DsaWithSha512);
//
// RFC 4491
//
noParams.Add(CryptoProObjectIdentifiers.GostR3411x94WithGostR3410x94);
noParams.Add(CryptoProObjectIdentifiers.GostR3411x94WithGostR3410x2001);
//
// explicit params
//
AlgorithmIdentifier sha1AlgId = new AlgorithmIdentifier(OiwObjectIdentifiers.IdSha1, DerNull.Instance);
m_exParams.Add("SHA1WITHRSAANDMGF1", CreatePssParams(sha1AlgId, 20));
AlgorithmIdentifier sha224AlgId = new AlgorithmIdentifier(NistObjectIdentifiers.IdSha224, DerNull.Instance);
m_exParams.Add("SHA224WITHRSAANDMGF1", CreatePssParams(sha224AlgId, 28));
AlgorithmIdentifier sha256AlgId = new AlgorithmIdentifier(NistObjectIdentifiers.IdSha256, DerNull.Instance);
m_exParams.Add("SHA256WITHRSAANDMGF1", CreatePssParams(sha256AlgId, 32));
AlgorithmIdentifier sha384AlgId = new AlgorithmIdentifier(NistObjectIdentifiers.IdSha384, DerNull.Instance);
m_exParams.Add("SHA384WITHRSAANDMGF1", CreatePssParams(sha384AlgId, 48));
AlgorithmIdentifier sha512AlgId = new AlgorithmIdentifier(NistObjectIdentifiers.IdSha512, DerNull.Instance);
m_exParams.Add("SHA512WITHRSAANDMGF1", CreatePssParams(sha512AlgId, 64));
}
/**
* Return the digest algorithm using one of the standard JCA string
* representations rather than the algorithm identifier (if possible).
*/
private static string GetDigestAlgName(
DerObjectIdentifier digestAlgOID)
{
if (PkcsObjectIdentifiers.MD5.Equals(digestAlgOID))
{
return "MD5";
}
else if (OiwObjectIdentifiers.IdSha1.Equals(digestAlgOID))
{
return "SHA1";
}
else if (NistObjectIdentifiers.IdSha224.Equals(digestAlgOID))
{
return "SHA224";
}
else if (NistObjectIdentifiers.IdSha256.Equals(digestAlgOID))
{
return "SHA256";
}
else if (NistObjectIdentifiers.IdSha384.Equals(digestAlgOID))
{
return "SHA384";
}
else if (NistObjectIdentifiers.IdSha512.Equals(digestAlgOID))
{
return "SHA512";
}
else if (NistObjectIdentifiers.IdSha512_224.Equals(digestAlgOID))
{
return "SHA512(224)";
}
else if (NistObjectIdentifiers.IdSha512_256.Equals(digestAlgOID))
{
return "SHA512(256)";
}
else if (TeleTrusTObjectIdentifiers.RipeMD128.Equals(digestAlgOID))
{
return "RIPEMD128";
}
else if (TeleTrusTObjectIdentifiers.RipeMD160.Equals(digestAlgOID))
{
return "RIPEMD160";
}
else if (TeleTrusTObjectIdentifiers.RipeMD256.Equals(digestAlgOID))
{
return "RIPEMD256";
}
else if (CryptoProObjectIdentifiers.GostR3411.Equals(digestAlgOID))
{
return "GOST3411";
}
else if (RosstandartObjectIdentifiers.id_tc26_gost_3411_12_256.Equals(digestAlgOID))
{
return "GOST3411-2012-256";
}
else if (RosstandartObjectIdentifiers.id_tc26_gost_3411_12_512.Equals(digestAlgOID))
{
return "GOST3411-2012-512";
}
else
{
return digestAlgOID.Id;
}
}
internal static string GetSignatureName(AlgorithmIdentifier sigAlgId)
{
Asn1Encodable parameters = sigAlgId.Parameters;
if (parameters != null && !DerNull.Instance.Equals(parameters))
{
if (sigAlgId.Algorithm.Equals(PkcsObjectIdentifiers.IdRsassaPss))
{
RsassaPssParameters rsaParams = RsassaPssParameters.GetInstance(parameters);
return GetDigestAlgName(rsaParams.HashAlgorithm.Algorithm) + "withRSAandMGF1";
}
if (sigAlgId.Algorithm.Equals(X9ObjectIdentifiers.ECDsaWithSha2))
{
Asn1Sequence ecDsaParams = Asn1Sequence.GetInstance(parameters);
return GetDigestAlgName((DerObjectIdentifier)ecDsaParams[0]) + "withECDSA";
}
}
return sigAlgId.Algorithm.Id;
}
private static RsassaPssParameters CreatePssParams(
AlgorithmIdentifier hashAlgId,
int saltSize)
{
return new RsassaPssParameters(
hashAlgId,
new AlgorithmIdentifier(PkcsObjectIdentifiers.IdMgf1, hashAlgId),
new DerInteger(saltSize),
new DerInteger(1));
}
internal static DerObjectIdentifier GetAlgorithmOid(string algorithmName)
{
if (m_algorithms.TryGetValue(algorithmName, out var oid))
return oid;
return new DerObjectIdentifier(algorithmName);
}
internal static AlgorithmIdentifier GetSigAlgID(DerObjectIdentifier sigOid, string algorithmName)
{
if (noParams.Contains(sigOid))
return new AlgorithmIdentifier(sigOid);
if (m_exParams.TryGetValue(algorithmName, out var explicitParameters))
return new AlgorithmIdentifier(sigOid, explicitParameters);
return new AlgorithmIdentifier(sigOid, DerNull.Instance);
}
internal static IEnumerable<string> GetAlgNames()
{
return CollectionUtilities.Proxy(m_algorithms.Keys);
}
}
/// <summary>
/// Calculator factory class for signature generation in ASN.1 based profiles that use an AlgorithmIdentifier to preserve
/// signature algorithm details.
/// </summary>
public class Asn1SignatureFactory
: ISignatureFactory
{
private readonly AlgorithmIdentifier algID;
private readonly string algorithm;
private readonly AsymmetricKeyParameter privateKey;
private readonly SecureRandom random;
/// <summary>
/// Base constructor.
/// </summary>
/// <param name="algorithm">The name of the signature algorithm to use.</param>
/// <param name="privateKey">The private key to be used in the signing operation.</param>
public Asn1SignatureFactory (string algorithm, AsymmetricKeyParameter privateKey)
: this(algorithm, privateKey, null)
{
}
/// <summary>
/// Constructor which also specifies a source of randomness to be used if one is required.
/// </summary>
/// <param name="algorithm">The name of the signature algorithm to use.</param>
/// <param name="privateKey">The private key to be used in the signing operation.</param>
/// <param name="random">The source of randomness to be used in signature calculation.</param>
public Asn1SignatureFactory(string algorithm, AsymmetricKeyParameter privateKey, SecureRandom random)
{
if (algorithm == null)
throw new ArgumentNullException("algorithm");
if (privateKey == null)
throw new ArgumentNullException("privateKey");
if (!privateKey.IsPrivate)
throw new ArgumentException("Key for signing must be private", "privateKey");
DerObjectIdentifier sigOid = X509Utilities.GetAlgorithmOid(algorithm);
this.algorithm = algorithm;
this.privateKey = privateKey;
this.random = random;
this.algID = X509Utilities.GetSigAlgID(sigOid, algorithm);
}
public object AlgorithmDetails
{
get { return this.algID; }
}
public IStreamCalculator<IBlockResult> CreateCalculator()
{
ISigner signer = SignerUtilities.InitSigner(algorithm, true, privateKey, random);
return new DefaultSignatureCalculator(signer);
}
/// <summary>
/// Allows enumeration of the signature names supported by the verifier provider.
/// </summary>
public static IEnumerable<string> SignatureAlgNames
{
get { return X509Utilities.GetAlgNames(); }
}
}
/// <summary>
/// Verifier class for signature verification in ASN.1 based profiles that use an AlgorithmIdentifier to preserve
/// signature algorithm details.
/// </summary>
public class Asn1VerifierFactory
: IVerifierFactory
{
private readonly AlgorithmIdentifier algID;
private readonly AsymmetricKeyParameter publicKey;
/// <summary>
/// Base constructor.
/// </summary>
/// <param name="algorithm">The name of the signature algorithm to use.</param>
/// <param name="publicKey">The public key to be used in the verification operation.</param>
public Asn1VerifierFactory(string algorithm, AsymmetricKeyParameter publicKey)
{
if (algorithm == null)
throw new ArgumentNullException("algorithm");
if (publicKey == null)
throw new ArgumentNullException("publicKey");
if (publicKey.IsPrivate)
throw new ArgumentException("Key for verifying must be public", "publicKey");
DerObjectIdentifier sigOid = X509Utilities.GetAlgorithmOid(algorithm);
this.publicKey = publicKey;
this.algID = X509Utilities.GetSigAlgID(sigOid, algorithm);
}
public Asn1VerifierFactory(AlgorithmIdentifier algorithm, AsymmetricKeyParameter publicKey)
{
this.publicKey = publicKey;
this.algID = algorithm;
}
public object AlgorithmDetails
{
get { return this.algID; }
}
public IStreamCalculator<IVerifier> CreateCalculator()
{
ISigner verifier = SignerUtilities.InitSigner(X509Utilities.GetSignatureName(algID), false, publicKey, null);
return new DefaultVerifierCalculator(verifier);
}
}
/// <summary>
/// Provider class which supports dynamic creation of signature verifiers.
/// </summary>
public class Asn1VerifierFactoryProvider: IVerifierFactoryProvider
{
private readonly AsymmetricKeyParameter publicKey;
/// <summary>
/// Base constructor - specify the public key to be used in verification.
/// </summary>
/// <param name="publicKey">The public key to be used in creating verifiers provided by this object.</param>
public Asn1VerifierFactoryProvider(AsymmetricKeyParameter publicKey)
{
this.publicKey = publicKey;
}
public IVerifierFactory CreateVerifierFactory(object algorithmDetails)
{
return new Asn1VerifierFactory((AlgorithmIdentifier)algorithmDetails, publicKey);
}
/// <summary>
/// Allows enumeration of the signature names supported by the verifier provider.
/// </summary>
public IEnumerable<string> SignatureAlgNames
{
get { return X509Utilities.GetAlgNames(); }
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 669c608b479683645946ae90e8249f53
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,61 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.Collections.Generic;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Nist;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Ntt;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Cms;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Operators;
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Operators
{
public class CmsContentEncryptorBuilder
{
private static readonly IDictionary<DerObjectIdentifier, int> KeySizes =
new Dictionary<DerObjectIdentifier, int>();
static CmsContentEncryptorBuilder()
{
KeySizes[NistObjectIdentifiers.IdAes128Cbc] = 128;
KeySizes[NistObjectIdentifiers.IdAes192Cbc] = 192;
KeySizes[NistObjectIdentifiers.IdAes256Cbc] = 256;
KeySizes[NttObjectIdentifiers.IdCamellia128Cbc] = 128;
KeySizes[NttObjectIdentifiers.IdCamellia192Cbc] = 192;
KeySizes[NttObjectIdentifiers.IdCamellia256Cbc] = 256;
}
private static int GetKeySize(DerObjectIdentifier oid)
{
return KeySizes.TryGetValue(oid, out var keySize) ? keySize : -1;
}
private readonly DerObjectIdentifier encryptionOID;
private readonly int keySize;
private readonly EnvelopedDataHelper helper = new EnvelopedDataHelper();
//private SecureRandom random;
public CmsContentEncryptorBuilder(DerObjectIdentifier encryptionOID)
: this(encryptionOID, GetKeySize(encryptionOID))
{
}
public CmsContentEncryptorBuilder(DerObjectIdentifier encryptionOID, int keySize)
{
this.encryptionOID = encryptionOID;
this.keySize = keySize;
}
public ICipherBuilderWithKey Build()
{
//return new Asn1CipherBuilderWithKey(encryptionOID, keySize, random);
return new Asn1CipherBuilderWithKey(encryptionOID, keySize, null);
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d7f51c38d59535c4a9c834a0b14d39d9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,34 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Cms;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.X509;
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Operators
{
/// <deprecated>Use KeyTransRecipientInfoGenerator</deprecated>
public class CmsKeyTransRecipientInfoGenerator
: KeyTransRecipientInfoGenerator
{
public CmsKeyTransRecipientInfoGenerator(X509Certificate recipCert, IKeyWrapper keyWrapper)
: base(new Asn1.Cms.IssuerAndSerialNumber(recipCert.IssuerDN, new DerInteger(recipCert.SerialNumber)), keyWrapper)
{
}
public CmsKeyTransRecipientInfoGenerator(IssuerAndSerialNumber issuerAndSerial, IKeyWrapper keyWrapper)
: base(issuerAndSerial, keyWrapper)
{
}
public CmsKeyTransRecipientInfoGenerator(byte[] subjectKeyID, IKeyWrapper keyWrapper) : base(subjectKeyID, keyWrapper)
{
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 08cdce98bc25d844a9b641acdce1dcd5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,32 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.IO;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.IO;
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Operators
{
public class DefaultSignatureCalculator
: IStreamCalculator<IBlockResult>
{
private readonly SignerSink mSignerSink;
public DefaultSignatureCalculator(ISigner signer)
{
this.mSignerSink = new SignerSink(signer);
}
public Stream Stream
{
get { return mSignerSink; }
}
public IBlockResult GetResult()
{
return new DefaultSignatureResult(mSignerSink.Signer);
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8b7e0d64f42c7674f9a6c61d3bc522a9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,40 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Operators
{
public class DefaultSignatureResult
: IBlockResult
{
private readonly ISigner mSigner;
public DefaultSignatureResult(ISigner signer)
{
this.mSigner = signer;
}
public byte[] Collect()
{
return mSigner.GenerateSignature();
}
public int Collect(byte[] sig, int sigOff)
{
byte[] signature = Collect();
signature.CopyTo(sig, sigOff);
return signature.Length;
}
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
public int Collect(Span<byte> destination)
{
byte[] result = Collect();
result.CopyTo(destination);
return result.Length;
}
#endif
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 18e6fc5e606f7224288826aa8f27858a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,32 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.IO;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.IO;
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Operators
{
public class DefaultVerifierCalculator
: IStreamCalculator<IVerifier>
{
private readonly SignerSink mSignerSink;
public DefaultVerifierCalculator(ISigner signer)
{
this.mSignerSink = new SignerSink(signer);
}
public Stream Stream
{
get { return mSignerSink; }
}
public IVerifier GetResult()
{
return new DefaultVerifierResult(mSignerSink.Signer);
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 89a4491c375b08c4f9603effdd075d93
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,33 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Operators
{
public class DefaultVerifierResult
: IVerifier
{
private readonly ISigner mSigner;
public DefaultVerifierResult(ISigner signer)
{
this.mSigner = signer;
}
public bool IsVerified(byte[] signature)
{
return mSigner.VerifySignature(signature);
}
public bool IsVerified(byte[] sig, int sigOff, int sigLen)
{
byte[] signature = Arrays.CopyOfRange(sig, sigOff, sigOff + sigLen);
return IsVerified(signature);
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9969699bdddfa3e43bfb48f74bed62ae
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,44 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Operators
{
public class GenericKey
{
private readonly AlgorithmIdentifier algorithmIdentifier;
private readonly object representation;
public GenericKey(object representation)
{
this.algorithmIdentifier = null;
this.representation = representation;
}
public GenericKey(AlgorithmIdentifier algorithmIdentifier, byte[] representation)
{
this.algorithmIdentifier = algorithmIdentifier;
this.representation = representation;
}
public GenericKey(AlgorithmIdentifier algorithmIdentifier, object representation)
{
this.algorithmIdentifier = algorithmIdentifier;
this.representation = representation;
}
public AlgorithmIdentifier AlgorithmIdentifier
{
get { return algorithmIdentifier; }
}
public object Representation
{
get { return representation; }
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 49b5df0387026814e93adf97bafc27b1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: