public byte[] GetBytes() { if (_algorithm == null) { throw new CryptographicException("No algorithm OID specified"); } ASN1 aSN = new ASN1(48); aSN.Add(ASN1Convert.FromOid(_algorithm)); if (_iterations > 0 || _salt != null) { ASN1 asn = new ASN1(4, _salt); ASN1 asn2 = ASN1Convert.FromInt32(_iterations); ASN1 aSN2 = new ASN1(48); aSN2.Add(asn); aSN2.Add(asn2); aSN.Add(aSN2); } ASN1 asn3 = new ASN1(4, _data); ASN1 aSN3 = new ASN1(48); aSN3.Add(aSN); aSN3.Add(asn3); return(aSN3.GetBytes()); }
// Note: PKCS#8 doesn't define how to generate the key required for encryption // so you're on your own. Just don't try to copy the big guys too much ;) // Netscape: http://www.cs.auckland.ac.nz/~pgut001/pubs/netscape.txt // Microsoft: http://www.cs.auckland.ac.nz/~pgut001/pubs/breakms.txt public byte[] GetBytes() { if (_algorithm == null) { throw new CryptographicException("No algorithm OID specified"); } ASN1 encryptionAlgorithm = new ASN1(0x30); encryptionAlgorithm.Add(ASN1Convert.FromOid(_algorithm)); // parameters ANY DEFINED BY algorithm OPTIONAL if ((_iterations > 0) || (_salt != null)) { ASN1 salt = new ASN1(0x04, _salt); ASN1 iterations = ASN1Convert.FromInt32(_iterations); ASN1 parameters = new ASN1(0x30); parameters.Add(salt); parameters.Add(iterations); encryptionAlgorithm.Add(parameters); } // encapsulates EncryptedData into an OCTET STRING ASN1 encryptedData = new ASN1(0x04, _data); ASN1 encryptedPrivateKeyInfo = new ASN1(0x30); encryptedPrivateKeyInfo.Add(encryptionAlgorithm); encryptedPrivateKeyInfo.Add(encryptedData); return(encryptedPrivateKeyInfo.GetBytes()); }
public byte[] GetBytes() { if (this._algorithm == null) { throw new CryptographicException("No algorithm OID specified"); } ASN1 asn = new ASN1(48); asn.Add(ASN1Convert.FromOid(this._algorithm)); if (this._iterations > 0 || this._salt != null) { ASN1 asn2 = new ASN1(4, this._salt); ASN1 asn3 = ASN1Convert.FromInt32(this._iterations); ASN1 asn4 = new ASN1(48); asn4.Add(asn2); asn4.Add(asn3); asn.Add(asn4); } ASN1 asn5 = new ASN1(4, this._data); ASN1 asn6 = new ASN1(48); asn6.Add(asn); asn6.Add(asn5); return(asn6.GetBytes()); }
public byte[] GetBytes() { if (this._algorithm == null) { throw new CryptographicException("No algorithm OID specified"); } ASN1 asn1_1 = new ASN1((byte)48); asn1_1.Add(ASN1Convert.FromOid(this._algorithm)); if (this._iterations > 0 || this._salt != null) { ASN1 asn1_2 = new ASN1((byte)4, this._salt); ASN1 asn1_3 = ASN1Convert.FromInt32(this._iterations); ASN1 asn1_4 = new ASN1((byte)48); asn1_4.Add(asn1_2); asn1_4.Add(asn1_3); asn1_1.Add(asn1_4); } ASN1 asn1_5 = new ASN1((byte)4, this._data); ASN1 asN1 = new ASN1((byte)48); asN1.Add(asn1_1); asN1.Add(asn1_5); return(asN1.GetBytes()); }
public void ConvertInt32_Positive() { Int32 expected = Int32.MaxValue; ASN1 integer = ASN1Convert.FromInt32(expected); Int32 actual = ASN1Convert.ToInt32(integer); Assert.AreEqual(expected, actual, "Int32_Positive"); }
public void ConvertInt32_One() { Int32 expected = 1; ASN1 integer = ASN1Convert.FromInt32(expected); Int32 actual = ASN1Convert.ToInt32(integer); Assert.AreEqual(expected, actual, "Int32_Zero"); }
public void ConvertInt32_Negative() { Int32 expected = -1; ASN1 integer = ASN1Convert.FromInt32(expected); Int32 actual = ASN1Convert.ToInt32(integer); Assert.AreEqual(expected, actual, "Int32_Negative"); }
protected override void Encode() { ASN1 seq = new ASN1(0x30); if (cA) { seq.Add(new ASN1(0x01, new byte[] { 0xFF })); } // CAs MUST NOT include the pathLenConstraint field unless the cA boolean is asserted if (cA && (pathLenConstraint >= 0)) { seq.Add(ASN1Convert.FromInt32(pathLenConstraint)); } extnValue = new ASN1(0x04); extnValue.Add(seq); }
protected override void Encode() { ASN1 aSN = new ASN1(48); if (cA) { aSN.Add(new ASN1(1, new byte[1] { 255 })); } if (cA && pathLenConstraint >= 0) { aSN.Add(ASN1Convert.FromInt32(pathLenConstraint)); } extnValue = new ASN1(4); extnValue.Add(aSN); }
protected override void Encode() { ASN1 asn = new ASN1(48); if (this.cA) { asn.Add(new ASN1(1, new byte[] { byte.MaxValue })); } if (this.cA && this.pathLenConstraint >= 0) { asn.Add(ASN1Convert.FromInt32(this.pathLenConstraint)); } this.extnValue = new ASN1(4); this.extnValue.Add(asn); }
internal byte[] Encode() { ASN1 ex = new ASN1(0x30); if (_certificateAuthority) { ex.Add(new ASN1(0x01, new byte[] { 0xFF })); } if (_hasPathLengthConstraint) { // MS encodes the 0 (pathLengthConstraint is OPTIONAL) // and in a long form (02 00 versus 02 01 00) if (_pathLengthConstraint == 0) { ex.Add(new ASN1(0x02, new byte[] { 0x00 })); } else { ex.Add(ASN1Convert.FromInt32(_pathLengthConstraint)); } } return(ex.GetBytes()); }
internal byte[] Encode() { ASN1 asn = new ASN1(48); if (this._certificateAuthority) { asn.Add(new ASN1(1, new byte[] { byte.MaxValue })); } if (this._hasPathLengthConstraint) { if (this._pathLengthConstraint == 0) { asn.Add(new ASN1(2, new byte[1])); } else { asn.Add(ASN1Convert.FromInt32(this._pathLengthConstraint)); } } return(asn.GetBytes()); }