mirror of
https://github.com/hakril/PythonForWindows
synced 2026-06-08 14:31:45 +00:00
More doc + fix sample on windows.crypto
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
``windows.crypto`` -- CryptoAPI
|
||||
*******************************
|
||||
|
||||
.. module:: windows.crypto
|
||||
|
||||
The :mod:`windows.crypto` module offers some wrappers arround the CryptoAPI_.
|
||||
|
||||
The main goal of this module (for now) is providing simple encryption/decryption methods.
|
||||
|
||||
Encryption
|
||||
""""""""""
|
||||
|
||||
.. note::
|
||||
|
||||
See sample :ref:`sample_crypto_encryption`
|
||||
|
||||
encrypt
|
||||
'''''''
|
||||
|
||||
.. autofunction:: encrypt
|
||||
|
||||
decrypt
|
||||
'''''''
|
||||
|
||||
.. autofunction:: decrypt
|
||||
|
||||
import_pfx
|
||||
''''''''''
|
||||
|
||||
.. autofunction:: import_pfx
|
||||
|
||||
|
||||
Certificate
|
||||
"""""""""""
|
||||
|
||||
.. note::
|
||||
|
||||
See sample :ref:`sample_crypto_certificate`
|
||||
|
||||
CertificateContext
|
||||
''''''''''''''''''
|
||||
|
||||
.. autoclass:: CertificateContext
|
||||
|
||||
EHCERTSTORE
|
||||
'''''''''''
|
||||
|
||||
.. autoclass:: EHCERTSTORE
|
||||
|
||||
|
||||
CryptContext
|
||||
''''''''''''
|
||||
|
||||
.. autoclass:: CryptContext
|
||||
|
||||
|
||||
Generating componants
|
||||
"""""""""""""""""""""
|
||||
|
||||
.. module:: windows.crypto.generation
|
||||
|
||||
This module is used to generate selfsigned-certificates / keypair and pfx file.
|
||||
|
||||
.. note::
|
||||
|
||||
See ``genkeys()`` in the sample :ref:`sample_crypto_encryption`
|
||||
|
||||
|
||||
generate_selfsigned_certificate
|
||||
'''''''''''''''''''''''''''''''
|
||||
|
||||
.. autofunction:: generate_selfsigned_certificate
|
||||
|
||||
|
||||
generate_key
|
||||
''''''''''''
|
||||
|
||||
.. autofunction:: generate_key
|
||||
|
||||
|
||||
generate_pfx
|
||||
''''''''''''
|
||||
|
||||
.. autofunction:: generate_pfx
|
||||
|
||||
|
||||
|
||||
|
||||
.. _CryptoAPI: https://msdn.microsoft.com/en-us/library/windows/desktop/aa380252(v=vs.85).aspx
|
||||
+38
-5
@@ -525,7 +525,7 @@ This sample is a working POC able to generate key-pair, encrypt and decrypt file
|
||||
|
||||
Ouput::
|
||||
|
||||
(cmd λ) python ..\samples\encryption_demo.py genkey YOLOCERTIF mykey --pfxpassword MYPASSWORD
|
||||
(cmd λ) python samples\encryption_demo.py genkey YOLOCERTIF mykey --pfxpassword MYPASSWORD
|
||||
<CertificatContext "YOLOCERTIF" serial="1b a4 3e 17 f7 ed ec ab 4f f8 11 46 48 e9 29 25">
|
||||
|
||||
(cmd λ) ls
|
||||
@@ -533,7 +533,7 @@ Ouput::
|
||||
|
||||
(cmd λ) echo|set /p="my secret message" > message.txt
|
||||
|
||||
(cmd λ) python ..\samples\encryption_demo.py crypt message.txt message.crypt mykey.cer
|
||||
(cmd λ) python samples\encryption_demo.py crypt message.txt message.crypt mykey.cer
|
||||
Encryption done. Result:
|
||||
bytearray(b'0\x82\x01\x19\x06\t*\x86H\x86\xf7\r\x01\x07\x03\xa0\x82\x01\n0\x82\x01\x06\x02\x01\x001\x81\xc30\x81
|
||||
\xc0\x02\x01\x000)0\x151\x130\x11\x06\x03U\x04\x03\x13\nYOLOCERTIF\x02\x10\x1b\xa4>\x17\xf7\xed\xec\xabO\xf8\x11
|
||||
@@ -543,7 +543,7 @@ Ouput::
|
||||
\xc6\x12x\x1am\xc8\x01t\xac\xa6\xf3#\x02\xd4J \x8eZ\xbb\x10W\xe1 0;\x06\t*\x86H\x86\xf7\r\x01\x07\x010\x14\x06\x08*
|
||||
\x86H\x86\xf7\r\x03\x07\x04\x08\x14F\x04\xad\xed9\xed<\x80\x18\x80]6\xccTV\xbc\xb8*\x84QY!~\xb3\n\x1aV\xd4\rf\xd1n:')
|
||||
|
||||
(cmd λ) python ..\samples\encryption_demo.py decrypt message.crypt mykey.pfx BADPASS
|
||||
(cmd λ) python samples\encryption_demo.py decrypt message.crypt mykey.pfx BADPASS
|
||||
Traceback (most recent call last):
|
||||
File "..\samples\encryption_demo.py", line 103, in <module>
|
||||
res.func(**res.__dict__)
|
||||
@@ -559,5 +559,38 @@ Ouput::
|
||||
raise Kernel32Error(func_name)
|
||||
windows.winproxy.Kernel32Error: PFXImportCertStore: [Error 86] The specified network password is not correct.
|
||||
|
||||
(cmd λ) python ..\samples\encryption_demo.py decrypt message.crypt mykey.pfx MYPASSWORD
|
||||
Result = <my secret message>
|
||||
(cmd λ) python samples\encryption_demo.py decrypt message.crypt mykey.pfx MYPASSWORD
|
||||
Result = <my secret message>
|
||||
|
||||
|
||||
.. _sample_crypto_certificate:
|
||||
|
||||
Certificate demo
|
||||
''''''''''''''''
|
||||
|
||||
.. literalinclude:: ..\..\samples\certificate.py
|
||||
|
||||
|
||||
Ouput::
|
||||
|
||||
|
||||
(cmd λ) python .\samples\certificate.py
|
||||
Analysing certificate: <CertificateContext "Microsoft Windows" serial="33 00 00 01 06 6e c3 25 c4 31 c9 18 0e 00 00 00 00 01 06">
|
||||
* name: <Microsoft Windows>
|
||||
* issuer: <Microsoft Windows Production PCA 2011>
|
||||
* raw_serial: <[51, 0, 0, 1, 6, 110, 195, 37, 196, 49, 201, 24, 14, 0, 0, 0, 0, 1, 6]>
|
||||
* serial: <33 00 00 01 06 6e c3 25 c4 31 c9 18 0e 00 00 00 00 01 06>
|
||||
* encoded start: <bytearray(b'0\x82\x05\x040\x82\x03\xec\xa0\x03\x02\x01\x02\x02\x133\x00\x00\x01\x06')>
|
||||
|
||||
This certificate has 1 certificate chain
|
||||
Chain 0:
|
||||
<CertificateContext "Microsoft Windows" serial="33 00 00 01 06 6e c3 25 c4 31 c9 18 0e 00 00 00 00 01 06">:
|
||||
* issuer: <Microsoft Windows Production PCA 2011>
|
||||
<CertificateContext "Microsoft Windows Production PCA 2011" serial="61 07 76 56 00 00 00 00 00 08">:
|
||||
* issuer: <Microsoft Root Certificate Authority 2010>
|
||||
<CertificateContext "Microsoft Root Certificate Authority 2010" serial="28 cc 3a 25 bf ba 44 ac 44 9a 9b 58 6b 43 39 aa">:
|
||||
* issuer: <Microsoft Root Certificate Authority 2010>
|
||||
|
||||
Looking for <Microsoft Root Certificate Authority 2010> in trusted certificates
|
||||
matches = [<CertificateContext "Microsoft Root Certificate Authority 2010" serial="28 cc 3a 25 bf ba 44 ac 44 9a 9b 58 6b 43 39 aa">]
|
||||
Found it !
|
||||
Reference in New Issue
Block a user