Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>PyCrypto has no function, which can manage RSA passphrase. </p> <p>Instead, You can use <strong>ezPyCrypto</strong> (<a href="http://freenet.mcnabhosting.com/ezPyCrypto/" rel="nofollow noreferrer">homepage</a>) module, which is built top of PyCrypto module. It has simpler interface and lets you: </p> <ul> <li>Generate, export and import public and private keys</li> <li>Encrypt and decrypt strings with ease</li> <li>Optionally create encrypted data as email-friendly text</li> <li>Sign and verify strings (incl. documents)</li> <li><strong>Protect your private key with a passphrase</strong></li> <li>Create 'streams', for sending data through secured sockets</li> <li>Choose any public key size you like (2048-bit recommended)</li> <li>Choose between RSA and ElGamal for public key, and IDEA, DES3, Blowfish, ARC4, IDEA for session key</li> <li>Rest in the comfort of security, with 256-bit session keys and defences against common RSA and ElGamal attacks, which will painfully frustrate anyone seeking to violate your privacy.</li> </ul> <p><strong>Usage:</strong></p> <pre><code>""" example7.py Demonstrate the use of passphrases with private keys """ import ezPyCrypto mysecret = "Don't look at this!!!" raw = "Here is a string to encrypt" # Create a key object k = ezPyCrypto.key(passphrase=mysecret) # Export public/private key publicAndPrivateKey = k.exportKeyPrivate() # Encrypt against this keypair enc = k.encString(raw) # Create a new key object, and import keys (with passphrase) k1 = ezPyCrypto.key(publicAndPrivateKey, passphrase=mysecret) # Decrypt text dec = k.decString(enc) # test if dec == raw: print "Successful decryption using correct passphrase" else: print "Failed somewhere" print "Trying now with a bad passphrase" try: k2 = ezPyCrypto.key(publicAndPrivateKey, passphrase="cracking attempt") except ezPyCrypto.CryptoKeyError: print "Oops - our feeble cracking attempt failed (which is a good thing)." else: print "Cracking attempt succeeded - we're not safe" # We're in - let's plunder dec2 = k2.decString(enc) </code></pre> <p><strong>Build it</strong></p> <p>If you look into ezCryptoPy source,then you'll see key is actually encrypted/decrypted by using BlueFish algorithm:</p> <pre><code> # decrypt against passphrase blksiz = 8 # lazy of me # create temporary symmetric cipher object for passphrase - #hardwire to Blowfish ppCipher = Blowfish.new(passphrase, Blowfish.MODE_CFB, self._passIV[0:blksiz]) enclen = len(keyobj) decpriv = '' i = 0 while i &lt; enclen: decbit = ppCipher.decrypt(keyobj[i:i+blksiz]) decpriv += decbit i += blksiz keyobj = decpriv[0:size] </code></pre> <p>That means, you can write your own passphrase handler by using previous code example without installing ezPyCrypto. Here can you find many code examples, how do to it yourself: <a href="http://nullege.com/codes/search/Crypto.PublicKey.RSA" rel="nofollow noreferrer">Nullege code search</a></p> <p><strong>My first and alternative solution:</strong></p> <p>You can use python <em>exec()</em> function and commandline function "ssh-keygen"(<a href="http://kimmo.suominen.com/docs/ssh/#passwd" rel="nofollow noreferrer">doc</a>):</p> <p><code>ssh-keygen -p [-P old_passphrase] [-N new_passphrase] [-f keyfile]</code>. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload