本文整理汇总了C#中Mono.Security.ASN1类的典型用法代码示例。如果您正苦于以下问题:C# ASN1类的具体用法?C# ASN1怎么用?C# ASN1使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ASN1类属于Mono.Security命名空间,在下文中一共展示了ASN1类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessSpnegoInitialContextTokenRequest
// Class(60) {
// OID(spnego),
// Class(A0) {
// Class(30) {
// Class(A0) {
// Class(30) { OID,OID,OID} },
// Class(A2) { OctetStream } } } }
public byte [] ProcessSpnegoInitialContextTokenRequest ()
{
Type1Message type1 = new Type1Message (NtlmVersion.Version3);
type1.Flags = unchecked ((NtlmFlags) 0xE21882B7);
type1.Domain = "WORKGROUP"; // FIXME: remove it
ASN1 asn = new ASN1 (0x60);
ASN1 asn2 = new ASN1 (0xA0);
ASN1 asn21 = new ASN1 (0x30);
ASN1 asn211 = new ASN1 (0xA0);
ASN1 asn2111 = new ASN1 (0x30);
asn211.Add (asn2111);
asn2111.Add (ASN1Convert.FromOid (Constants.OidNtlmSsp));
asn2111.Add (ASN1Convert.FromOid (Constants.OidKerberos5));
asn2111.Add (ASN1Convert.FromOid (Constants.OidMIT));
ASN1 asn212 = new ASN1 (0xA2);
ASN1 asn2121 = new ASN1 (0x4);
asn2121.Value = type1.GetBytes ();
asn212.Add (asn2121);
asn21.Add (asn211);
asn21.Add (asn212);
asn2.Add (asn21);
asn.Add (ASN1Convert.FromOid (Constants.OidSpnego));
asn.Add (asn2);
return asn.GetBytes ();
}
示例2: ConvertDateTimeInvalidButExistingFormat
[Test]
public void ConvertDateTimeInvalidButExistingFormat ()
{
string nosecs = "9912312359Z";
ASN1 dt = new ASN1 (0x18, Encoding.ASCII.GetBytes (nosecs));
DateTime actual = ASN1Convert.ToDateTime (dt);
AssertEquals ("DateTime", nosecs, actual.ToUniversalTime ().ToString ("yyMMddHHmm") + "Z");
示例3: ToOid
// Convert a binary encoded OID to human readable string representation of
// an OID (IETF style). Based on DUMPASN1.C from Peter Gutmann.
static public string ToOid(ASN1 asn1)
{
if (asn1 == null)
throw new ArgumentNullException("asn1");
byte[] aOID = asn1.Value;
StringBuilder sb = new StringBuilder();
// Pick apart the OID
byte x = (byte)(aOID[0] / 40);
byte y = (byte)(aOID[0] % 40);
if (x > 2)
{
// Handle special case for large y if x = 2
y += (byte)((x - 2) * 40);
x = 2;
}
sb.Append(x.ToString(CultureInfo.InvariantCulture));
sb.Append(".");
sb.Append(y.ToString(CultureInfo.InvariantCulture));
ulong val = 0;
for (x = 1; x < aOID.Length; x++)
{
val = ((val << 7) | ((byte)(aOID[x] & 0x7F)));
if (!((aOID[x] & 0x80) == 0x80))
{
sb.Append(".");
sb.Append(val.ToString(CultureInfo.InvariantCulture));
val = 0;
}
}
return sb.ToString();
}
示例4: AlgorithmIdentifier
static public ASN1 AlgorithmIdentifier (string oid)
{
ASN1 ai = new ASN1 (0x30);
ai.Add (ASN1Convert.FromOid (oid));
ai.Add (new ASN1 (0x05)); // NULL
return ai;
}
示例5: Decode
protected override void Decode ()
{
ASN1 sequence = new ASN1 (extnValue.Value);
if (sequence.Tag != 0x04)
throw new ArgumentException ("Invalid SubjectKeyIdentifier extension");
ski = sequence.Value;
}
示例6: GeneralNames
public GeneralNames (ASN1 sequence)
{
for (int i = 0; i < sequence.Count; i++) {
switch (sequence[i].Tag) {
case 0x81: // rfc822Name [1] IA5String
if (rfc822Name == null)
rfc822Name = new ArrayList ();
rfc822Name.Add (Encoding.ASCII.GetString (sequence[i].Value));
break;
case 0x82: // dNSName [2] IA5String
if (dnsName == null)
dnsName = new ArrayList ();
dnsName.Add (Encoding.ASCII.GetString (sequence[i].Value));
break;
case 0x84: // directoryName [4] Name
case 0xA4:
if (directoryNames == null)
directoryNames = new ArrayList ();
directoryNames.Add (X501.ToString (sequence[i][0]));
break;
case 0x86: // uniformResourceIdentifier [6] IA5String
if (uris == null)
uris = new ArrayList ();
uris.Add (Encoding.ASCII.GetString (sequence[i].Value));
break;
case 0x87: // iPAddress [7] OCTET STRING
if (ipAddr == null)
ipAddr = new ArrayList ();
// TODO - Must find sample certificates
break;
default:
break;
}
}
}
示例7: Attribute
static public ASN1 Attribute (string oid, ASN1 value)
{
ASN1 attr = new ASN1 (0x30);
attr.Add (ASN1Convert.FromOid (oid));
ASN1 aset = attr.Add (new ASN1 (0x31));
aset.Add (value);
return attr;
}
示例8: Encode
protected override void Encode ()
{
if (extnValue == null) {
extnValue = new ASN1 (0x30);
foreach (string oid in keyPurpose) {
extnValue.Add (ASN1Convert.FromOid (oid));
}
}
}
示例9: Encode
protected override void Encode ()
{
if (ski == null) {
throw new InvalidOperationException ("Invalid SubjectKeyIdentifier extension");
}
var seq = new ASN1 (0x04, ski);
extnValue = new ASN1 (0x04);
extnValue.Add (seq);
}
示例10: Decode
protected override void Decode ()
{
keyPurpose = new ArrayList ();
ASN1 sequence = new ASN1 (extnValue.Value);
if (sequence.Tag != 0x30)
throw new ArgumentException ("Invalid ExtendedKeyUsage extension");
// for every policy OID
for (int i=0; i < sequence.Count; i++)
keyPurpose.Add (ASN1Convert.ToOid (sequence [i]));
}
示例11: ConvertDateTimeInvalidButExistingFormat
public void ConvertDateTimeInvalidButExistingFormat ()
{
string nosecs = "9912312359Z";
ASN1 dt = new ASN1 (0x18, Encoding.ASCII.GetBytes (nosecs));
DateTime actual = ASN1Convert.ToDateTime (dt);
#if NET_2_0
Assert.AreEqual (DateTimeKind.Utc, actual.Kind, "Kind");
#endif
Assert.AreEqual (nosecs, actual.ToUniversalTime ().ToString ("yyMMddHHmm") + "Z", "DateTime");
}
示例12: Encode
protected override void Encode ()
{
ASN1 seq = new ASN1 (0x30);
foreach (string oid in keyPurpose) {
seq.Add (ASN1Convert.FromOid (oid));
}
extnValue = new ASN1 (0x04);
extnValue.Add (seq);
}
示例13: X509ExtensionCollection
public X509ExtensionCollection (ASN1 asn1) : this ()
{
readOnly = true;
if (asn1 == null)
return;
if (asn1.Tag != 0x30)
throw new Exception ("Invalid extensions format");
for (int i=0; i < asn1.Count; i++) {
X509Extension extension = new X509Extension (asn1 [i]);
InnerList.Add (extension);
}
}
示例14: ToString
static public string ToString (ASN1 seq)
{
StringBuilder sb = new StringBuilder ();
for (int i = 0; i < seq.Count; i++) {
ASN1 entry = seq [i];
AppendEntry (sb, entry, true);
// separator (not on last iteration)
if (i < seq.Count - 1)
sb.Append (", ");
}
return sb.ToString ();
}
示例15: Decode
protected override void Decode ()
{
// default values
cA = false;
pathLenConstraint = 0; // no constraint
ASN1 sequence = new ASN1 (extnValue.Value);
if (sequence.Tag != 0x30)
throw new ArgumentException ("Invalid BasicConstraints extension");
int n = 0;
ASN1 a = sequence [n++];
if ((a != null) && (a.Tag == 0x01)) {
cA = (a.Value [0] == 0xFF);
a = sequence [n++];
}
if ((a != null) && (a.Tag == 0x02))
pathLenConstraint = ASN1Convert.ToInt32 (a);
}