< Back

Get-ASN1ValueLength

Fri Jan 10, 2020 8:59 pm

NAME Get-ASN1ValueLength



SYNOPSIS

Gets the length of the value of the ASN.1 structure.





SYNTAX

Get-ASN1ValueLength [-Reader] <BinaryReader> [-UseLongLengthFormat] [<CommonParameters>]





DESCRIPTION

This cmdlet reads the length of the ASN.1 property. The BinaryReader input position should be

on the byte directly after the tag value. After the cmdlet is executed, the reader is advanced

the length of the bytes used to represent the value length and will be on the first byte of the

value so it is prepared to read the value bytes next.





PARAMETERS

-Reader <BinaryReader>

The BinaryReader that is being used to read the byte stream containing the ASN1 structure



Required? true

Position? 1

Default value

Accept pipeline input? true (ByValue)

Accept wildcard characters? false



-UseLongLengthFormat [<SwitchParameter>]

This switch indicates that the ASN.1 property uses a multi-byte length format, such as a Sequence or Octet

String.



Required? false

Position? named

Default value False

Accept pipeline input? false

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS

System.IO.BinaryReader





OUTPUTS

System.UInt32





NOTES





AUTHOR: Michael Haken

LAST UPDATE: 1/22/2018



-------------------------- EXAMPLE 1 --------------------------



PS C:\\>$Content = Get-Content -Path c:\\cert.pem -Raw



$Bytes = [System.Convert]::FromBase64String($Content)

[System.IO.MemoryStream]$MS = New-Object -TypeName System.IO.MemoryStream($Bytes)

[System.IO.BinaryReader]$Reader = New-Object -TypeName System.IO.BinaryReader($MS)

[System.Byte]$Tag = $Reader.ReadByte()

[System.UInt32]$Length = Get-ASN1ValueLength -Reader $Reader

[System.Byte[]]$Value = $Reader.GetBytes($Length)



This example shows how to retrieve the length of the ASN.1 property indicated by the $Tag value. The cert.pem file

contains

only a base64 encoded string of a structure using the ASN.1 format.











RELATED LINKS