4

Is there a way to use python to encrypt/decrypt a file (something like Axcrypt)?

3
  • is the ruby tag there by accident? I would fix it for you, but I can't... Commented Aug 12, 2010 at 19:08
  • Did you mean to tag this with python instead of ruby, or are the title and question body in error? Commented Aug 12, 2010 at 19:08
  • was there a ruby tag? sorry didn't notice it Commented Aug 13, 2010 at 11:12

4 Answers 4

1

How about this SO Q&A, which talks about encrypting/decrypting with PGP?

Sign up to request clarification or add additional context in comments.

Comments

1

check http://github.com/slideinc/PyECC , http://sourceforge.net/projects/cryptopy/ and http://www.dlitz.net/software/pycrypto/ (found all by search "crypto" at http://pypi.python.org/pypi )

Comments

0

Go here in the python docs for modules available for encryption: http://docs.python.org/library/crypto.html

Comments

0

You can try this for encrypting as well as decrypting..

#!/usr/bin/env python2.7
# -*- coding: utf-8 -*-
import nacl.secret
import nacl.utils
import base64
from pyblake2 import blake2b
import getpass

print "### ENCRYPTION"
key = blake2b(digest_size=16)
key.update(getpass.getpass("PASSWORD:"))
key = key.hexdigest()

print "key: %s" % key
box = nacl.secret.SecretBox(key)

# This is our message to send, it must be a bytestring as SecretBox will
#   treat is as just a binary blob of data.
msg = b"whohooäööppöööo"
print "msg: %s" % msg
nonce = nacl.utils.random(nacl.secret.SecretBox.NONCE_SIZE)
print "nonce: %s" % nacl.encoding.HexEncoder.encode(nonce)
encrypted = box.encrypt(msg, nonce, encoder=nacl.encoding.HexEncoder)
print "cipher: %s " % encrypted

print "### DECRYPTION"
key = blake2b(digest_size=16)
key.update(getpass.getpass("PASSWORD:"))
key = key.hexdigest()

nonce = None
print "nonce: %s" % nonce
print "key: %s" % key
box = nacl.secret.SecretBox(key)

msg = encrypted
print "msg: %s" % msg

plain = box.decrypt(ciphertext=msg,encoder=nacl.encoding.HexEncoder)
print "plain: %s" % plain

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.