This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func getTlsCertFromPkcs12(certFile, pw string) (tls.Certificate, error) { | |
bytes, err := os.ReadFile(certFile) | |
if err != nil { | |
return tls.Certificate{}, err | |
} | |
blocks, err := pkcs12.ToPEM(bytes, pw) | |
if err != nil { | |
return tls.Certificate{}, err | |
} | |
pemData := []byte{} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Net; | |
using System.Text; | |
namespace HttpListener; | |
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
using var listener = new System.Net.HttpListener(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
conn, error: = net.Dial("udp", "8.8.8.8:80") | |
if error != nil { | |
fmt.Println(error) | |
} | |
defer conn.Close() | |
ipAddress: = conn.LocalAddr().( * net.UDPAddr) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Difference between | |
var m myStruct | |
json.Unmarshal(data, &m) | |
// and | |
m := &myStruct{} | |
json.Unmarshal(data, m) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"errors" | |
"fmt" | |
"log" | |
"net/http" | |
"os" | |
"os/exec" | |
"runtime" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func UnzipFile(zipFile, targetFolder string) error { | |
r, err := zip.OpenReader(zipFile) | |
if err != nil { | |
return err | |
} | |
for _, f := range r.File { | |
fh, err := f.Open() // NOTE: mit Open kann man nur lesen | |
if err != nil { | |
return err |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func decodeUTF16ToUTF8(b []byte, bigEndian bool) ([]byte, error) { | |
if len(b) % 2 != 0 { | |
return nil, fmt.Errorf("must have even length byte slice") | |
} | |
var ( | |
u16s = make([]uint16, 1) | |
ret = &bytes.Buffer{} | |
b8buf = make([]byte, 4) | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tlsConfig := &tls.Config{ | |
MinVersion: tls.VersionTLS12, | |
CurvePreferences: []tls.CurveID{tls.CurveP521, tls.CurveP384, tls.CurveP256}, | |
PreferServerCipherSuites: true, | |
CipherSuites: []uint16{ | |
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, | |
tls.TLS_RSA_WITH_AES_256_GCM_SHA384, | |
}, | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class Helper | |
{ | |
private static readonly Dictionary<string, string> Cache = new Dictionary<string, string>(); | |
public static string ReadUtf8EmbeddedRessource(string filename) | |
{ | |
string utf8EmbeddedRessource; | |
lock (Cache) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"crypto/tls" | |
"log" | |
) | |
func main() { | |
var cert tls.Certificate // from wherever | |
tlsConfig := &tls.Config{ |
NewerOlder