To be, or not to be, that is the question.

  • 上全局 VPN,不是 SS 的全局模式

  • 安利一下 TabNine 插件 at 2019年11月18日

    现在内存这么便宜,8G/200 块,如果是用的 Macbook,那还有什么说的,直接换 16 寸那款 64G 版本

  • 如果用 RESTful 的风格和你说的这种是不是冲突

    {
        "code": "...",
        "message": "...",
        "details": {}
    }
    
  • 服务器被墙了怎么办 at 2019年09月19日

    看过什么内容会不会有记录

  • 非对称加密,每次加密结果都会不一样

  • 尝试补全 go 的加密方法

    package main
    import (
        "crypto/rand"
        "crypto/rsa"
        "crypto/x509"
        "encoding/pem"
        "bytes"
        "encoding/base64"
        "fmt"
    )
    
    func SplitSubN(s string, n int) []string {
        sub := ""
        subs := []string{}
    
        runes := bytes.Runes([]byte(s))
        l := len(runes)
        for i, r := range runes {
            sub = sub + string(r)
            if (i + 1) % n == 0 {
                subs = append(subs, sub)
                sub = ""
            } else if (i + 1) == l {
                subs = append(subs, sub)
            }
        }
    
        return subs
    }
    
    func main() {
        data := "hello"
        const publickey = `
    -----BEGIN PUBLIC KEY-----
    MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDw8cUnDShPMYFDZkL65Y0nUyyN
    0Nqxgz6vsFEJj3I3A1nsaQBmGC1urtO9pGJkFzaXkQo7s2y+S53qdsWNufKk8U2l
    SpiGjm4WWCucJTnYpC+nMwAAd/nmQudCtH4czJOkK4m29Tv6fUmvOtcSpQzW7zL0
    47I6qkkAadGb8CAg9wIDAQAB
    -----END PUBLIC KEY-----`
        block, _ := pem.Decode([]byte(publickey))
        pubInterface, _ := x509.ParsePKIXPublicKey(block.Bytes)
        pub := pubInterface.(*rsa.PublicKey)
        partLen := pub.N.BitLen()/8 - 11
        fmt.Println(partLen)
        chunks := SplitSubN(data, partLen)
        buffer := bytes.NewBufferString("")
        for _, chunk := range chunks {
            bytes, err := rsa.EncryptPKCS1v15(rand.Reader, pub, []byte(chunk))
            if err != nil {
                fmt.Println("", err)
            }
            buffer.Write(bytes)
        }
        fmt.Println(base64.RawURLEncoding.EncodeToString(buffer.Bytes()))
    }
    
    #=> "runNVN4ZjB_Z-aA7-7ovGP4bVPNJdKpvXpR47Wn9mdvTYqhUp1z-vN_Q_mGylXH_y423cZyipKnZDEP0dTZFGMfsNhL81NOBNG981pQZ87t9_F2mnyqsoXOR6pUL7j4VQUExMsx3caeMOc_0KkQbjGGnbSvwQ9ewtH7UQBcYiUE"
    

    然后用 ruby 解密

    private_pem = <<-EOS
    -----BEGIN PRIVATE KEY-----
    MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAPDxxScNKE8xgUNm
    QvrljSdTLI3Q2rGDPq+wUQmPcjcDWexpAGYYLW6u072kYmQXNpeRCjuzbL5Lnep2
    xY258qTxTaVKmIaObhZYK5wlOdikL6czAAB3+eZC50K0fhzMk6Qribb1O/p9Sa86
    1xKlDNbvMvTjsjqqSQBp0ZvwICD3AgMBAAECgYBjForF7JtPNkS6uyuAkzbhnUsN
    Z38I0bjN9+zbyapnBXHNz8DiO78zbaKWsyvjjchdvMBAnSFzgRWIfx/vkTE/59GF
    gfn7VLbvKMYULzbkZbh8NcwNjJLfLtNXmqt973uSiNah9JTeCHQd062VI5D64QHv
    GgKMDAJ6Z2W4jSn8gQJBAPuXT0597Z3ciY6G0EHAhHrJNieDNJboUFodQlHqpTrs
    SLmGTJVswj3Su2vi7ZEPyErHjL2vdrs1hDXKFVik+rkCQQD1KrKA7xUdYRwGnIry
    CMH+uaECSmKhnZgFVg9zCSpDEaTOjenGGVuu6sXWmJKj7PZ1pFHsPrzOCSp/3Pk6
    hmEvAkBL22NeFzn9zvDquFsyeAl5vBFH+JdyqLkRcqD8cfM/wN5skcGljBVE7rTz
    4ogepNOPOHuG9dCmwYwLa9Lj11qBAkAafynZq31BtpwbztFphS7KQ++12qo8Q1cJ
    xJpY2XW61+5S8J2Cbn0tM2x8W/MFSnf8kOzVtpYbQnxYY16AR8O7AkEAkHLKWspk
    QFWRUlliBVpJg+GHe9VI7ND3wWIbV4H1kmyt08959LBpg7cZLu06PXUShwtADaE9
    42Ta3K/fSme4Tw==
    -----END PRIVATE KEY-----
    EOS
    
    s = 'KAPye436VwAqMZ6amu9UeODAh-3dhU6KNbcVXmBU-HK_geeHjyktLzOREMvWPnLcJ7mdddPwwHPEBZfaVliCFl0o9IDIUe7JfEHvmfG7limTUyii08O2b1cBu8pAnev3BxUfDJRqqh84-66Qiiur-syQQkAdnzH-wuG3DJ_UPgo'
    rsa = OpenSSL::PKey::RSA.new(private_pem)
    rsa.private_decrypt(Base64.urlsafe_decode64(s))
    

    成功解密出 hello

    然后用 ruby 加密

    public_pem = <<-EOS
    -----BEGIN PUBLIC KEY-----
    MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDw8cUnDShPMYFDZkL65Y0nUyyN
    0Nqxgz6vsFEJj3I3A1nsaQBmGC1urtO9pGJkFzaXkQo7s2y+S53qdsWNufKk8U2l
    SpiGjm4WWCucJTnYpC+nMwAAd/nmQudCtH4czJOkK4m29Tv6fUmvOtcSpQzW7zL0
    47I6qkkAadGb8CAg9wIDAQAB
    -----END PUBLIC KEY-----
    EOS
    
    data = 'hello'
    rsa = OpenSSL::PKey::RSA.new(public_pem)
    Base64.urlsafe_encode64 rsa.public_encrypt(data)
    

    用上面 ruby 的解密方法也能解密

    https://golang.org/pkg/crypto/rsa/#EncryptPKCS1v15

    https://ruby-doc.org/stdlib-2.5.1/libdoc/openssl/rdoc/OpenSSL/PKey/RSA.html#method-i-public_encrypt

    https://commondatastorage.googleapis.com/chromium-boringssl-docs/rsa.h.html#RSA_PKCS1_PADDING

    https://stackoverflow.com/questions/47981709/ruby-rsa-public-key-encryption-to-golang

    结论:你写的是对的

  • mongodb,pg 应该都有基于地理位置的查询功能

  • 代码自测程度是指哪些方法被修改了吗?

  • https://github.com/rest-client/rest-client/blob/master/lib/restclient/request.rb#L368

    如果 header 名是 symbol 格式会调用

    key = key.to_s.split(/_/).map(&:capitalize).join('-')

    可以改成

    heades: { 'appId' => 'xlkb' }

To be, or not to be, that is the question.