public static void ObjectIdentifier(byte[] value, byte[] expected) { var reader = new Asn1Reader(value); Assert.Equal(expected, reader.ObjectIdentifier().ToArray()); Assert.True(reader.SuccessComplete); }
internal override bool TryReadAlgorithmIdentifier( ref Asn1Reader reader, out ReadOnlySpan <byte> nonce) { bool success = true; reader.BeginSequence(); success &= reader.ObjectIdentifier().SequenceEqual(s_oid.Bytes); nonce = reader.OctetString(); success &= (nonce.Length == crypto_aead_chacha20poly1305_ietf_NPUBBYTES); reader.End(); success &= reader.Success; return(success); }
public static void PkixPublicKey() { var a = KeyAgreementAlgorithm.X25519; var b = Utilities.RandomBytes.Slice(0, a.PrivateKeySize); using var k = Key.Import(a, b, KeyBlobFormat.RawPrivateKey); var publicKeyBytes = k.Export(KeyBlobFormat.RawPublicKey); var blob = k.Export(KeyBlobFormat.PkixPublicKey); var reader = new Asn1Reader(blob); reader.BeginSequence(); reader.BeginSequence(); Assert.Equal(s_oid, reader.ObjectIdentifier().ToArray()); reader.End(); Assert.Equal(publicKeyBytes, reader.BitString().ToArray()); reader.End(); Assert.True(reader.SuccessComplete); }
public static void PkixPrivateKey() { var a = new X25519(); var b = Utilities.RandomBytes.Slice(0, a.PrivateKeySize); using (var k = Key.Import(a, b, KeyBlobFormat.RawPrivateKey, KeyExportPolicies.AllowPlaintextExport)) { var blob = k.Export(KeyBlobFormat.PkixPrivateKey); var reader = new Asn1Reader(blob); reader.BeginSequence(); Assert.Equal(0, reader.Integer32()); reader.BeginSequence(); Assert.Equal(s_oid, reader.ObjectIdentifier().ToArray()); reader.End(); var curvePrivateKey = new Asn1Reader(reader.OctetString()); Assert.Equal(b.ToArray(), curvePrivateKey.OctetString().ToArray()); Assert.True(curvePrivateKey.SuccessComplete); reader.End(); Assert.True(reader.SuccessComplete); } }
public static void PkixPrivateKey() { var a = new X25519(); var b = Utilities.RandomBytes.Slice(0, a.PrivateKeySize); using (var k = Key.Import(a, b, KeyBlobFormat.RawPrivateKey, KeyFlags.AllowExport)) { var blob = new ReadOnlySpan <byte>(k.Export(KeyBlobFormat.PkixPrivateKey)); var reader = new Asn1Reader(ref blob); reader.BeginSequence(); Assert.Equal(0, reader.Integer32()); reader.BeginSequence(); Assert.Equal(s_oid, reader.ObjectIdentifier().ToArray()); reader.End(); var edPrivateKey = reader.OctetString(); reader.End(); Assert.True(reader.SuccessComplete); var reader2 = new Asn1Reader(ref edPrivateKey); Assert.Equal(b.ToArray(), reader2.OctetString().ToArray()); Assert.True(reader2.SuccessComplete); } }