-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from pavel-v-chernykh/introduce-key-password
Introduce key password
- Loading branch information
Showing
9 changed files
with
196 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module github.com/pavel-v-chernykh/keystore-go/v3/examples/keypass | ||
|
||
go 1.14 | ||
|
||
require github.com/pavel-v-chernykh/keystore-go/v3 v3.0.0 | ||
|
||
replace github.com/pavel-v-chernykh/keystore-go/v3 v3.0.0 => ../.. |
Binary file not shown.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package main | ||
|
||
import ( | ||
"crypto/x509" | ||
"log" | ||
"os" | ||
|
||
"github.com/pavel-v-chernykh/keystore-go/v3" | ||
) | ||
|
||
func readKeyStore(filename string, storePassword []byte, keysPasswords ...keystore.KeyPassword) keystore.KeyStore { | ||
f, err := os.Open(filename) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer func() { | ||
if err := f.Close(); err != nil { | ||
log.Fatal(err) | ||
} | ||
}() | ||
keyStore, err := keystore.Decode(f, storePassword, keysPasswords...) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
return keyStore | ||
} | ||
|
||
func zeroing(s []byte) { | ||
for i := 0; i < len(s); i++ { | ||
s[i] = 0 | ||
} | ||
} | ||
|
||
// keytool -genkeypair -alias alias -storepass password -keypass keypassword -keyalg RSA -keystore keystore.jks | ||
func main() { | ||
password := []byte{'p', 'a', 's', 's', 'w', 'o', 'r', 'd'} | ||
defer zeroing(password) | ||
|
||
keyPassword := []byte{'k', 'e', 'y', 'p', 'a', 's', 's', 'w', 'o', 'r', 'd'} | ||
defer zeroing(password) | ||
|
||
kp := keystore.KeyPassword{Alias: "alias", Password: keyPassword} | ||
ks := readKeyStore("keystore.jks", password, kp) | ||
|
||
entry := ks["alias"] | ||
privKeyEntry := entry.(*keystore.PrivateKeyEntry) | ||
|
||
key, err := x509.ParsePKCS8PrivateKey(privKeyEntry.PrivateKey) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
log.Printf("%#v", key) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
-----BEGIN PRIVATE KEY----- | ||
MIIEwAIBADANBgkqhkiG9w0BAQEFAASCBKowggSmAgEAAoIBAQCTjd1HLf1DjOhC | ||
zQiXSHHRXg16qJpqavOU86S5vtgBuLS8a8b9aOEcBQ0H5Lj9GAm3zhKRB2zJ3Aab | ||
iQTCoYq7qbafGmGW7sBNuf0/lCjvnk4wWHsPSqD9SbaQMz6VDCBoCAhykiweAlsu | ||
ap4Niizl5QOVHkVfShUTObGs2T2FBkW249goxbQK+bpxWbXULktAY4qX8ENjU5oK | ||
fi60ZrmeyO0wh7eChqQXUaHthXI0PGbJzqEvC2JB6J0/asZTr6nBgOKvkQgfNbGR | ||
Q1e5xAu8pjcvNw5Pw5VuEfxtKpzA57BpMkv7mTYZfYguSQld+RnB71PIJnSLMcT8 | ||
GyaAJgOJAgMBAAECggEBAIcR3fVCjAxB+Hrt5WdW0ZmuVvhpTrELpl47ihbeNC2f | ||
PxMc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rmXHQn+ | ||
5sOgVEQqp3YKE+d9n4CgQaTAh4mcb2IJArt6r2+8Ez1G8WZvkMPubuE6jvzjBHWb | ||
1L+bIfsU3MsZ4xAaw3AKGzrOWIorlZIINFmuSetTP0Ee5S8ApSrzX/PFUQtJrg5z | ||
d22QeEAmL/nu/PvNC9KiwP9f0wY= | ||
-----END PRIVATE KEY----- |
This file contains 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
Binary file not shown.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
-----BEGIN PRIVATE KEY----- | ||
MIIEwAIBADANBgkqhkiG9w0BAQEFAASCBKowggSmAgEAAoIBAQCTjd1HLf1DjOhC | ||
zQiXSHHRXg16qJpqavOU86S5vtgBuLS8a8b9aOEcBQ0H5Lj9GAm3zhKRB2zJ3Aab | ||
iQTCoYq7qbafGmGW7sBNuf0/lCjvnk4wWHsPSqD9SbaQMz6VDCBoCAhykiweAlsu | ||
ap4Niizl5QOVHkVfShUTObGs2T2FBkW249goxbQK+bpxWbXULktAY4qX8ENjU5oK | ||
fi60ZrmeyO0wh7eChqQXUaHthXI0PGbJzqEvC2JB6J0/asZTr6nBgOKvkQgfNbGR | ||
Q1e5xAu8pjcvNw5Pw5VuEfxtKpzA57BpMkv7mTYZfYguSQld+RnB71PIJnSLMcT8 | ||
GyaAJgOJAgMBAAECggEBAIcR3fVCjAxB+Hrt5WdW0ZmuVvhpTrELpl47ihbeNC2f | ||
PxMcNdPTJf3YQc1v+kb0sjCnWyeXfGZsG0BVdR4VckHHYXzTUXIwq6h7EPAaWD7A | ||
0yI+XKfq0OQLjisCPc+Cgke40sLOO8Rcs8sRng0W53Kq6VSfmTFZR2GJ9rMbSc1y | ||
QfgTEuVDKKYAItwMZ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