CreatechStudio / ARSA

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

What is ARSA?

ARSA is a cross-platform RSA encryption and signature library. The key and text exported can be circulated in all languages that ARSA supports.

​ Most importantly, it is incredibly easy to master with a handful of actual code.

What can ARSA do?

  • Do standard RSA encryption and signature
  • Encrypt long texts
  • Cross platform
  • One single unified format in all languages

Catalogue

  1. Download and import
  2. Create new ARSA keys
  3. Import existed keys
  4. Export keys to Strings
  5. Encrypt
  6. Decrypt
  7. Make signatures
  8. Verify signatures
  9. Key objects conversion

How to use?

  1. Download and import

    JAVA

    Download source code (.java) here.

    import indi.atatc.arsa.ARSA;

    Python 3+

    Download source code (.py) here, or install through pip:

    Windows

    pip install arsa

    Linux

    pip3 install arsa
    from arsa import *
  2. Create new ARSA keys

    JAVA

    int keyLength;	// RSA key length, 2048 recommended
    ARSA.AKeyPair keyPair = ARSA.newkeys(keyLength);
    Get the public key:
    ARSA.APublicKey publicKey = keyPair.getPublicKey();
    Get the private key:
    ARSA.APrivateKey privateKey = keyPair.getPrivateKey();

    Python 3+

    key_pair = new_keys()

    or

    key_length: int	# RSA key length, 2048 in default
    key_pair = new_keys(key_length)
    Get the public key:
    public_key: APublicKey = key_pair.get_public_key()
    Get the private key:
    private_key: APrivateKey = key_pair.get_private_key()
  3. Import existed keys

    1. Public keys

      JAVA

      String publicKeyString;
      int keyLength;
      ARSA.APublicKey publicKey = ARSA.APublicKey.importPublicKey(publicKeyString, keyLength);

      or from java.security.PublicKey

      PublicKey publicKeyObject;
      int keyLength;
      ARSA.APublicKey publicKey = ARSA.APublicKey.importPublicKey(publicKeyObject, keyLength);

      Python 3+

      public_key_bytes: bytes
      key_length: int
      APublicKey public_key = APublicKey.import_public_key(public_key_bytes, key_length)
    2. Private keys

      Just change all the name "public" above to "private".

  4. Export keys to Strings

    1. Public keys

      JAVA

      ARSA.APublicKey publicKey;
      String publicKeyString = publicKey.toString();

      Python 3+

      public_key: APublicKey
      public_key_string: str = str(public_key)
    2. Private keys

      Just change all the name "public" above to "private".

  5. Encrypt

    JAVA

    ARSA.APublicKey publicKey;
    String plainText;
    String cipherText = ARSA.encrypt(plainText, publicKey);

    Python 3+

    public_key: APublicKey
    plain_text: str
    cipher_text: bytes = encrypt(plain_text, public_key);
  6. Decrypt

    JAVA

    ARSA.APrivateKey privateKey;
    String cipherText;
    String plainText = ARSA.decrypt(cipherText, privateKey);

    Python 3+

    private_key: APrivateKey
    cipher_text: base64.bytes_types
    plain_text: str = decrypt(cipher_text, private_key)
  7. Make signatures

    JAVA

    String content;
    ARSA.APrivateKey privateKey;
    String signature = ARSA.sign(content, privateKey);

    Python 3+

    content: base64.bytes_types
    private_key: APrivateKey
    signature: bytes = sign(content, private_key)
  8. Verify signatures

    JAVA

    String content;
    String signature;
    ARSA.APublicKey publicKey;
    boolean isQualified = ARSA.verify(content, signature, publicKey);

    Python 3+

    content: base64.bytes_types
    signature: bytes
    public_key: APublicKey
    bool is_qualified = verify(content, signature, public_key)
  9. Key objects conversion

    1. JAVA

      To java.security.PublicKey:
      APublicKey publicKey;
      PublicKey publicKeyObject = publicKey.getPublicKey();
      To java.security.PrivateKey:
      APrivateKey privateKey;
      PrivateKey privateKeyObject = privateKey.getPrivateKey();
    2. Python 3+

      To Crypto.PublicKey.RSA.PublicKey:
      public_key: APublicKey
      public_key_object: PublicKey = public_key.get_public_key()
      To Crypto.PublicKey.RSA.RsaKey:
      private_key: APrivateKey
      private_key_object: RsaKey = private_key.get_private_key()

About

License:MIT License


Languages

Language:Java 59.5%Language:Python 40.5%