fetchKey will load a a DER formatted key from disk
(filename string)
| 147 | |
| 148 | // fetchKey will load a a DER formatted key from disk |
| 149 | func (e *Encrypter) fetchKey(filename string) (*[32]byte, error) { |
| 150 | f, err := os.Open(filename) |
| 151 | if err != nil { |
| 152 | return nil, err |
| 153 | } |
| 154 | buf := new(bytes.Buffer) |
| 155 | io.Copy(buf, f) |
| 156 | |
| 157 | p, _ := pem.Decode(buf.Bytes()) |
| 158 | if p == nil { |
| 159 | return nil, errors.New("Failed to decode key") |
| 160 | } |
| 161 | var newKey [32]byte |
| 162 | copy(newKey[:], p.Bytes) |
| 163 | |
| 164 | return &newKey, nil |
| 165 | } |
| 166 | |
| 167 | // decodePublicKey will base64 decode the provided key to the box representation |
| 168 | func (e *Encrypter) decodePublicKey(key string) (*[32]byte, error) { |
no test coverage detected