Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: How to use GNU Crypto LIbrary in Matlab via Java Interface

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Location
    India
    Posts
    3
    My Mood
    Depressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question How to use GNU Crypto LIbrary in Matlab via Java Interface

    Hi All,

    I find it very difficult to do the encryption in matlab using GNU Crypto library



    One example given in a book Using Javax.crypto

    function e = encrypt(t, key)
    %ENCRYPT: e = encrypt(t, key)
    % Encrypt the plaintext string t into
    % the encrypted byte array e using a key
    % from getkey.
    import javax.crypto.*
    cipher = Cipher.getInstance('DESede') ;
    cipher.init(Cipher.ENCRYPT_MODE, key) ;
    e = cipher.doFinal(int8(t))' ;

    function t = decrypt(e, key)
    %DECRYPT: t = decrypt(e, key)
    % Decrypt the encrypted byte array e
    % into to plaintext string t using a key
    % from getkey.
    import javax.crypto.*
    cipher = Cipher.getInstance('DESede') ;
    cipher.init(Cipher.DECRYPT_MODE, key) ;
    t = char(cipher.doFinal(e))' ;


    function key = getkey(password)
    %GETKEY: key = getkey(password)
    % Converts a string into a key for use
    % in the encrypt and decrypt functions.
    % Uses triple DES.
    import javax.crypto.spec.*
    b = int8(password) ;
    n = length(b) ;
    b((n+1):24) = 0 ;
    b = b(1:24) ;
    key = SecretKeySpec(b, 'DESede') ;


    But i want to use

    Anubis
    gnu.crypto.cipher.Anubis

    h**p://www.gnu.org/software/gnu-crypto/manual/api/gnu/crypto/cipher/Anubis.html

    is it possible to do the same way as it is given in the javax.crypto case ?


  2. #2
    Junior Member
    Join Date
    Mar 2012
    Location
    India
    Posts
    3
    My Mood
    Depressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Re: How to use GNU Crypto LIbrary in Matlab via Java Interface

    I tried this ,but nothing happens

    %   public void encrypt(byte[] in,
    %                     int i,
    %                     byte[] out,
    %                     int j,
    %                     java.lang.Object k,
    %                     int bs)
    % 
    % 
    % 
    %     Encrypts exactly one block of plaintext.
    % 
    %     Parameters:
    %         in - the plaintext.
    %         i - index of in from which to start considering data.
    %         out - the ciphertext.
    %         j - index of out from which to store the result.
    %         k - the session key to use.
    %         bs - the block size to use.
    %
    %
    %
    % %public java.lang.Object makeKey(byte[] uk,
    %                                 int bs)
    %    throws java.security.InvalidKeyException
     
     
    clear all
    clc
     
    J1=javaObject('gnu.crypto.cipher.Anubis')
     
    in =uint8([zeros(1,16)]) ;
    out =uint8([zeros(1,16)]) ;
     
     
    bs=16;
     
    uk=logical([zeros(1,15),1]); 
     
     
    k=J1.makeKey(uk,bs);
     
    J1.encrypt(in,0,out,0,k,16)



    class Anubis

    Constructor Summary
    Anubis()
    Trivial 0-arguments constructor.

    Method Summary
    java.util.Iterator blockSizes()
    Returns an Iterator over the supported block sizes.
    java.lang.Object clone()
    Returns a clone of this instance.
    void decrypt(byte[] in, int i, byte[] out, int j, java.lang.Object k, int bs)
    Decrypts exactly one block of ciphertext.
    void encrypt(byte[] in, int i, byte[] out, int j, java.lang.Object k, int bs)
    Encrypts exactly one block of plaintext.
    java.util.Iterator keySizes()
    Returns an Iterator over the supported key sizes.
    java.lang.Object makeKey(byte[] uk, int bs)
    Expands a user-supplied key material into a session key for a designated block size.
    boolean selfTest()
    A correctness test that consists of basic symmetric encryption / decryption test(s) for all supported block and key sizes, as well as one (1) variable key Known Answer Test (KAT).

Similar Threads

  1. Java - Crypto ISBN number verification, GUI program
    By djl1990 in forum What's Wrong With My Code?
    Replies: 11
    Last Post: October 13th, 2011, 11:22 AM
  2. [SOLVED] UnsatisfiedLinkError from Matlab code
    By RandalF in forum Java Native Interface
    Replies: 2
    Last Post: August 18th, 2011, 09:42 AM
  3. Replies: 3
    Last Post: May 15th, 2010, 02:05 PM
  4. Replies: 0
    Last Post: May 3rd, 2010, 04:42 AM
  5. Replies: 1
    Last Post: October 7th, 2008, 07:35 AM