{"record":{"id":"06146c0c953045e7","repo":"peass-ng/PEASS-ng","slug":"failed-to-construct-octet-string-from-byte","errorCode":null,"errorMessage":"failed to construct OCTET STRING from byte[]: ","messagePattern":"failed to construct OCTET STRING from byte\\[\\]: ","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/asn1/Asn1OctetString.cs","lineNumber":56,"sourceCode":"         *\n         * @param obj the object we want converted.\n         * @exception ArgumentException if the object cannot be converted.\n         */\n        public static Asn1OctetString GetInstance(object obj)\n        {\n            if (obj == null || obj is Asn1OctetString)\n            {\n                return (Asn1OctetString)obj;\n            }\n            else if (obj is byte[])\n            {\n                try\n                {\n                    return GetInstance(FromByteArray((byte[])obj));\n                }\n                catch (IOException e)\n                {\n                    throw new ArgumentException(\"failed to construct OCTET STRING from byte[]: \" + e.Message);\n                }\n            }\n            // TODO: this needs to be deleted in V2\n            else if (obj is Asn1TaggedObject)\n            {\n                return GetInstance(((Asn1TaggedObject)obj).GetObject());\n            }\n            else if (obj is Asn1Encodable)\n            {\n                Asn1Object primitive = ((Asn1Encodable)obj).ToAsn1Object();\n\n                if (primitive is Asn1OctetString)\n                {\n                    return (Asn1OctetString)primitive;\n                }\n            }\n\n            throw new ArgumentException(\"illegal object in GetInstance: \" + Platform.GetTypeName(obj));","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/asn1/Asn1OctetString.cs#L38-L74","documentation":"Asn1OctetString.GetInstance, given a raw byte[], first parses it as an ASN.1 object; if parsing throws IOException it is rethrown as ArgumentException with this message. It means the byte[] you passed was expected to be an encoded OCTET STRING but is not decodable ASN.1 data.","triggerScenarios":"Calling Asn1OctetString.GetInstance(byte[]) where the byte[] is not a valid DER-encoded OCTET STRING (wrong content, truncated, or an entirely different ASN.1 structure that then fails inner GetInstance).","commonSituations":"Extracting a payload from a PKCS structure and re-wrapping it; passing raw plaintext bytes where DER-encoded bytes are required; off-by-one slicing of a decoded structure.","solutions":["If the bytes are raw data (not ASN.1), construct directly: new DerOctetString(bytes)","Validate the byte[] parses as DER before calling GetInstance (Asn1Object.FromByteArray in try/catch)","Check where the byte[] came from — re-derive from the parent ASN.1 structure instead of manual slicing","Log e.Message (appended to this error) to see the underlying parse failure"],"exampleFix":"// before\nAsn1OctetString s = Asn1OctetString.GetInstance(rawBytes); // raw, non-ASN.1 data\n// after\nAsn1OctetString s = new DerOctetString(rawBytes); // wrap raw data directly","handlingStrategy":"type-guard","validationCode":"bool IsDerEncoded(byte[] data) { try { Asn1Object.FromByteArray(data); return true; } catch { return false; } }","typeGuard":"bool IsOctetString(byte[] data) { try { return Asn1Object.FromByteArray(data) is Asn1OctetString; } catch { return false; } }","tryCatchPattern":"try { return Asn1OctetString.GetInstance(bytes); }\ncatch (ArgumentException) { return new DerOctetString(bytes); } // treat as raw data","preventionTips":["Use new DerOctetString(bytes) for raw data, GetInstance only for encoded data","Validate parseability with Asn1Object.FromByteArray first","Trace where the byte[] was sliced from to avoid off-by-one truncation"],"tags":["asn1","octet-string","argument","bouncycastle"],"backgroundTag":"invalid-asn1-data","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}