Skip to content

Commit c1493ad

Browse files
committed
allow cleartext keys
1 parent 131c460 commit c1493ad

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/cryptojwt/tools/keyconv.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,17 @@ def pem2jwk(filename: str, kid: str, kty: Optional[str] = None, private: bool =
8888
return jwk
8989

9090

91-
def export_jwk(jwk: JWK, private: bool = False) -> bytes:
91+
def export_jwk(jwk: JWK, private: bool = False, encrypt: bool = False) -> bytes:
9292
"""Export JWK as PEM/bin"""
9393

9494
if jwk.kty == 'oct':
9595
return jwk.key
9696

9797
if private:
98-
passphrase = getpass('Private key passphrase: ')
98+
if encrypt:
99+
passphrase = getpass('Private key passphrase: ')
100+
else:
101+
passphrase = None
99102
if passphrase:
100103
enc = serialization.BestAvailableEncryption(passphrase.encode())
101104
else:
@@ -149,6 +152,10 @@ def main():
149152
dest='private',
150153
action='store_true',
151154
help="Output private key")
155+
parser.add_argument('--encrypt',
156+
dest='encrypt',
157+
action='store_true',
158+
help="Encrypt private key")
152159
parser.add_argument('--output',
153160
dest='output',
154161
metavar='filename',
@@ -160,7 +167,7 @@ def main():
160167

161168
if f.endswith('.json'):
162169
jwk = jwk_from_file(f, args.private)
163-
serialized = export_jwk(jwk, args.private)
170+
serialized = export_jwk(jwk, private=args.private, encrypt=args.encrypt)
164171
output_bytes(data=serialized, binary=(jwk.kty == 'oct'), filename=args.output)
165172
elif f.endswith('.bin'):
166173
jwk = bin2jwk(filename=f, kid=args.kid)

0 commit comments

Comments
 (0)