https://github.com/phayes/decryptpem
Decrypts encrypted PEM files and blocks. Provides (optional) TTY prompt for input for password.
https://github.com/phayes/decryptpem
crypto cryptography decrypt dek golang password pem
Last synced: 5 months ago
JSON representation
Decrypts encrypted PEM files and blocks. Provides (optional) TTY prompt for input for password.
- Host: GitHub
- URL: https://github.com/phayes/decryptpem
- Owner: phayes
- License: bsd-3-clause
- Created: 2017-09-28T01:45:54.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-09-28T15:39:08.000Z (over 8 years ago)
- Last Synced: 2024-06-20T12:05:27.954Z (almost 2 years ago)
- Topics: crypto, cryptography, decrypt, dek, golang, password, pem
- Language: Go
- Homepage:
- Size: 12.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Decrypt PEM
[](https://travis-ci.org/phayes/decryptpem)
[](https://scrutinizer-ci.com/g/phayes/decryptpem/build-status/master)
[](https://goreportcard.com/report/github.com/phayes/decryptpem)
[](https://scrutinizer-ci.com/g/phayes/decryptpem/issues)
[](https://godoc.org/github.com/phayes/decryptpem)
Golang package that decrypts encrypted PEM files and blocks. Provides (optional) TTY prompt for input for password.
## Installation
```
go get github.com/phayes/decryptpem
```
## Example
```go
// Get private key, prompt for password and decrypt if necessary
pem, err := decryptpem.DecryptFileWithPrompt("/path/to/private_key.pem")
if err != nil {
log.Fatal(err)
}
privateKey, err := x509.ParsePKCS1PrivateKey(pem.Bytes());
if err != nil {
log.Fatal(err)
}
// It will also work with unencrypted plaintext PEM files
pem, err := decryptpem.DecryptFileWithPrompt("/path/to/plaintext_key.pem") // Will not prompt for pasword.
if err != nil {
log.Fatal(err)
}
privateKey, err := x509.ParsePKCS1PrivateKey(pem.Bytes());
if err != nil {
log.Fatal(err)
}
```
## Configuration
There are two configuration variables provided:
```go
// PasswordDelay sets the delay for any password tries and retries as a defence against brute force password guessing
// By default there is no delay
var decryptpem.PasswordDelay time.Duration
// MaxTries sets the maximum number of times a password may be tried before erroring out.
// A MaxTries of 1 means that there is only one try allowed (no retries)
// A MaxTries of 0 means infinite retries are allowed.
// When tries run out, an error of x509.IncorrectPasswordError will be returned.
var decryptpem.MaxTries int
```