本文整理汇总了C#中Org.BouncyCastle.Asn1.Asn1InputStream.ReadObject方法的典型用法代码示例。如果您正苦于以下问题:C# Asn1InputStream.ReadObject方法的具体用法?C# Asn1InputStream.ReadObject怎么用?C# Asn1InputStream.ReadObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Org.BouncyCastle.Asn1.Asn1InputStream
的用法示例。
在下文中一共展示了Asn1InputStream.ReadObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Parse
/**
* Parse the ServerCertificate message.
*
* @param is The stream where to parse from.
* @return A Certificate object with the certs, the server has sended.
* @throws IOException If something goes wrong during parsing.
*/
internal static Certificate Parse(
Stream inStr)
{
X509CertificateStructure[] certs;
int left = TlsUtilities.ReadUint24(inStr);
ArrayList tmp = new ArrayList();
while (left > 0)
{
int size = TlsUtilities.ReadUint24(inStr);
left -= 3 + size;
byte[] buf = new byte[size];
TlsUtilities.ReadFully(buf, inStr);
MemoryStream bis = new MemoryStream(buf, false);
Asn1InputStream ais = new Asn1InputStream(bis);
Asn1Object o = ais.ReadObject();
tmp.Add(X509CertificateStructure.GetInstance(o));
// if (bis.available() > 0)
if (bis.Position < bis.Length)
{
throw new ArgumentException("Sorry, there is garbage data left after the certificate");
}
}
// certs = new X509CertificateStructure[tmp.size()];
// for (int i = 0; i < tmp.size(); i++)
// {
// certs[i] = (X509CertificateStructure)tmp.elementAt(i);
// }
certs = (X509CertificateStructure[]) tmp.ToArray(typeof(X509CertificateStructure));
return new Certificate(certs);
}
示例2: DecodeFromDer
public static EcdsaSignature DecodeFromDer(byte[] bytes)
{
try
{
var decoder = new Asn1InputStream(bytes);
var seq = (Asn1Sequence)decoder.ReadObject();
DerInteger r, s;
try
{
r = (DerInteger)seq[0];
s = (DerInteger)seq[1];
}
catch (InvalidCastException)
{
return null;
}
decoder.Close();
// OpenSSL deviates from the DER spec by interpreting these values as unsigned, though they should not be
// Thus, we always use the positive versions. See: http://r6.ca/blog/20111119T211504Z.html
return new EcdsaSignature(r.PositiveValue, s.PositiveValue);
}
catch (IOException e)
{
throw new ApplicationException("Decoding form DER failed", e);
}
}
示例3: readTimeStampResp
private static TimeStampResp readTimeStampResp(
Asn1InputStream input)
{
try
{
return TimeStampResp.GetInstance(input.ReadObject());
}
catch (ArgumentException e)
{
throw new TspException("malformed timestamp response: " + e, e);
}
catch (InvalidCastException e)
{
throw new TspException("malformed timestamp response: " + e, e);
}
catch (EndOfStreamException e)
{
//jbonilla - TSA del BCE por alguna razón devuelve "null\n"
string resp = "";
if (input.CanSeek && input.CanRead && input.Length > 0)
{
input.Seek(0, SeekOrigin.Begin);
resp = Strings.FromByteArray(
Org.BouncyCastle.Utilities.IO.Streams.ReadAll(input));
}
throw new TspException("malformed timestamp response: "
+ resp + " " + e.Message, e);
}
}
示例4: GetAuthorityKeyFromCertificate
public static string GetAuthorityKeyFromCertificate(X509Certificate2 certificate)
{
try
{
foreach (var extension in certificate.Extensions.Cast<X509Extension>()
.Where(extension => extension.Oid.Value.Equals(AuthorityKeyOid)))
{
using (var asnStream = new Asn1InputStream(extension.RawData))
{
var asnObject = asnStream.ReadObject();
var taggedObject = new DerTaggedObject(0, asnObject);
var authorityKey = AuthorityKeyIdentifier.GetInstance(taggedObject, true);
var octetString = new DerOctetString(authorityKey.GetKeyIdentifier());
return NormalizeOctetString(octetString.ToString());
}
}
return "";
}
catch (Exception e)
{
Log.WarnFormat("An issue occurred while attempting to extract the authority key from a certificate: {0}", e.Message);
return "";
}
}
示例5: Check
public virtual bool Check(CertificateAndContext cert)
{
//TODO jbonilla - Validar
//byte[] qcStatement = cert.GetCertificate().GetExtensionValue(X509Extensions.QCStatements);
Asn1OctetString qcStatement = cert.GetCertificate().GetExtensionValue(X509Extensions.QCStatements);
if (qcStatement != null)
{
try
{
//Asn1InputStream input = new Asn1InputStream(qcStatement);
//DerOctetString s = (DerOctetString)input.ReadObject();
DerOctetString s = (DerOctetString)qcStatement;
byte[] content = s.GetOctets();
Asn1InputStream input = new Asn1InputStream(content);
DerSequence seq = (DerSequence)input.ReadObject();
for (int i = 0; i < seq.Count; i++)
{
QCStatement statement = QCStatement.GetInstance(seq[i]);
if (statement.StatementId.Id.Equals(qcStatementId))
{
return true;
}
}
return false;
}
catch (IOException e)
{
throw new RuntimeException(e);
}
}
return false;
}
示例6: Check
public virtual bool Check(CertificateAndContext cert)
{
//TODO jbonilla - validar.
//byte[] certificatePolicies = cert.GetCertificate().GetExtensionValue(X509Extensions.CertificatePolicies);
Asn1OctetString certificatePolicies = cert.GetCertificate().GetExtensionValue(X509Extensions.CertificatePolicies);
if (certificatePolicies != null)
{
try
{
//Asn1InputStream input = new Asn1InputStream(certificatePolicies);
//DerOctetString s = (DerOctetString)input.ReadObject();
DerOctetString s = (DerOctetString)certificatePolicies;
byte[] content = s.GetOctets();
Asn1InputStream input = new Asn1InputStream(content);
DerSequence seq = (DerSequence)input.ReadObject();
for (int i = 0; i < seq.Count; i++)
{
PolicyInformation policyInfo = PolicyInformation.GetInstance(seq[i]);
if (policyInfo.PolicyIdentifier.Id.Equals(policyOid))
{
return true;
}
}
}
catch (IOException e)
{
throw new RuntimeException(e);
}
}
return false;
}
示例7: ReadDerCrossCertificatePair
private X509CertificatePair ReadDerCrossCertificatePair(
Stream inStream)
{
Asn1InputStream dIn = new Asn1InputStream(inStream);//, ProviderUtil.getReadLimit(in));
Asn1Sequence seq = (Asn1Sequence)dIn.ReadObject();
CertificatePair pair = CertificatePair.GetInstance(seq);
return new X509CertificatePair(pair);
}
示例8: ExtractCrlDistributionPointsExtension
static CrlDistPoint ExtractCrlDistributionPointsExtension(X509Certificate2 certificate)
{
var bouncyCastleCertificate = new X509CertificateParser().ReadCertificate(certificate.RawData);
var extension = bouncyCastleCertificate.GetExtensionValue(new DerObjectIdentifier(ObjectIdentifiers.CrlDistributionPointsExtension));
var stream = new Asn1InputStream(extension.GetOctetStream());
return CrlDistPoint.GetInstance(stream.ReadObject());
}
示例9: SODFile
/// <summary>
/// Constructs a new EF_SOD file.
/// </summary>
/// <param name="data">bytes of the EF_DG1 file</param>
public SODFile(byte[] data)
{
MemoryStream dataStream = new MemoryStream(data);
BERTLVInputStream tlvStream = new BERTLVInputStream(dataStream);
int tag = tlvStream.readTag();
if (tag != IDGFile.EF_SOD_TAG) throw new ArgumentException("Expected EF_SOD_TAG");
int length = tlvStream.readLength();
Asn1InputStream sodAsn1 = new Asn1InputStream(dataStream);
DerSequence seq = (DerSequence)sodAsn1.ReadObject();
DerObjectIdentifier objectIdentifier = (DerObjectIdentifier)seq[0];
//DerTaggedObject o = (DerTaggedObject)seq[1];
DerSequence s2 = (DerSequence)((DerTaggedObject)seq[1]).GetObject();
IEnumerator e = s2.GetEnumerator();
e.MoveNext();
DerInteger version = (DerInteger)e.Current;
e.MoveNext();
Asn1Set digestAlgorithms = (Asn1Set)e.Current;
e.MoveNext();
ContentInfo contentInfo = ContentInfo.GetInstance(e.Current);
Asn1Set signerInfos = null;
bool certsBer = false;
bool crlsBer = false;
Asn1Set certificates = null;
Asn1Set crls = null;
while (e.MoveNext())
{
Object o = e.Current;
if (o is Asn1TaggedObject)
{
Asn1TaggedObject tagged = (Asn1TaggedObject)o;
switch (tagged.TagNo)
{
case 0:
certsBer = tagged is BerTaggedObject;
certificates = Asn1Set.GetInstance(tagged, false);
break;
case 1:
crlsBer = tagged is BerTaggedObject;
crls = Asn1Set.GetInstance(tagged, false);
break;
default:
throw new ArgumentException("unknown tag value " + tagged.TagNo);
}
}
else
{
signerInfos = (Asn1Set)o;
}
}
_signedData = new SignedData(digestAlgorithms, contentInfo, certificates, crls, signerInfos);
byte[] content = ((DerOctetString)contentInfo.Content).GetOctets();
Asn1InputStream inStream = new Asn1InputStream(content);
_lds = new LdsSecurityObject((Asn1Sequence)inStream.ReadObject());
}
示例10: verifySignature
public Boolean verifySignature(Byte[] data, Byte[] sig)
{
ECDsaSigner signer = new ECDsaSigner();
signer.Init(false, new ECPublicKeyParameters(ecParams.Curve.DecodePoint(pubKey), ecParams));
using (Asn1InputStream asn1stream = new Asn1InputStream(sig))
{
Asn1Sequence seq = (Asn1Sequence)asn1stream.ReadObject();
return signer.VerifySignature(data, ((DerInteger)seq[0]).PositiveValue, ((DerInteger)seq[1]).PositiveValue);
}
}
示例11: Main
public static void Main(string[] args)
{
FileStream fIn = new FileStream(args[0], FileMode.Open);
Asn1InputStream bIn = new Asn1InputStream(fIn);
Asn1Object obj;
while ((obj = bIn.ReadObject()) != null)
{
Console.WriteLine(Asn1Dump.DumpAsString(obj));
}
}
示例12: OcspResp
private OcspResp(
Asn1InputStream aIn)
{
try
{
this.resp = OcspResponse.GetInstance(aIn.ReadObject());
}
catch (Exception e)
{
throw new IOException("malformed response: " + e.Message, e);
}
}
示例13: Main
public static void Main(string[] args)
{
FileStream fIn = File.OpenRead(args[0]);
Asn1InputStream bIn = new Asn1InputStream(fIn);
Asn1Object obj;
while ((obj = bIn.ReadObject()) != null)
{
System.Diagnostics.Debug.WriteLine(Asn1Dump.DumpAsString(obj));
}
bIn.Close();
}
示例14: GetCertificatePolicyOid
public static String GetCertificatePolicyOid(X509Certificate2 certificate)
{
var extensions = GetX509Extensions(certificate);
var e = extensions.GetExtension(X509Extensions.CertificatePolicies);
var extIn = new Asn1InputStream(e.Value.GetOctetStream());
var piSeq = (DerSequence)extIn.ReadObject();
if (piSeq.Count != 1)
{
throw new NonOcesCertificateException("Could not find Certificate PolicyOID");
}
var pi = PolicyInformation.GetInstance(piSeq[0]);
return pi.PolicyIdentifier.Id;
}
示例15: generateSign
public static string generateSign(byte[] data, ICipherParameters privkey) {
var dsa = SignerUtilities.GetSigner (ECDSA);
dsa.Init (true, privkey);
dsa.BlockUpdate (data, 0, data.Length);
var sign = dsa.GenerateSignature ();
BigInteger r, s;
using (var decoder = new Asn1InputStream (sign)) {
var seq = (Asn1Sequence)decoder.ReadObject ();
r = ((DerInteger)seq [0]).Value;
s = ((DerInteger)seq [1]).Value;
}
var signature = packInto32 (r) + packInto32 (s);
return signature;
}