Skip to content

Commit

Permalink
hls解密服务
Browse files Browse the repository at this point in the history
  • Loading branch information
lilang committed Sep 29, 2022
1 parent ff4eda3 commit 924c051
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions example/CI/media_process/hls_decrypt_server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package main

import (
"encoding/base64"
"fmt"
"net"
"net/http"
"net/url"
"os"

kms "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/kms/v20190118"
)

func handler(w http.ResponseWriter, r *http.Request) {
m, err := url.ParseQuery(r.URL.RawQuery)
if err != nil {
fmt.Fprint(w, err.Error())
return
}

ciphertext := m.Get("Ciphertext")
kmsRegion := m.Get("KMSRegion")
if len(ciphertext) == 0 || len(kmsRegion) == 0 {
fmt.Fprint(w, "Ciphertext or KMSRegion is empty")
return
}

c, err := kms.NewClientWithSecretId(os.Getenv("COS_SECRETID"), os.Getenv("COS_SECRETKEY"), kmsRegion)
if err != nil {
fmt.Fprint(w, err.Error())
return
}

req := kms.NewDecryptRequest()
req.CiphertextBlob = &ciphertext
rsp, err := c.Decrypt(req)
if err != nil {
fmt.Fprint(w, err.Error())
return
}
s, err := base64.StdEncoding.DecodeString(*rsp.Response.Plaintext)
if err != nil {
fmt.Fprint(w, err.Error())
return
}
fmt.Fprint(w, string(s))
}

func GetLocalIp() string {
localIP := "127.0.0.1"
addrSlice, err := net.InterfaceAddrs()
if nil == err {
for _, addr := range addrSlice {
if ipnet, ok := addr.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
if nil != ipnet.IP.To4() {
localIP = ipnet.IP.String()
break
}
}
}
}
return localIP
}

func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(GetLocalIp()+":8082", nil)
}

0 comments on commit 924c051

Please sign in to comment.