From: smith grit on 3 Feb 2010 03:44 hello! I download this program. But i can't run this. when I run aescrypt('aaaa',1010') the output 103 26 101 247 255 39 32 208 166 221 79 70 100 249 86 36 %%%%%%%%%%%% function ct = aescrypt(pt,key) % AESCRYPT - encrypt a message using 128-bit AES % % USAGE: ct = aescrypt(pt,key) % % pt = plaintext, a vector in char or uint8 form % key = encryption key, which must be a character string or uint8 vector % ct = cyphertext % % Notes: (1) This function requires Java, which contains the encryption % routines. % (2) The provided key may have any (nonzero) length. It is hashed % to 128 bits using the MD5 hash algorithm. % (3) Use this function with the separate DZIP routine to enable % encryption of several Matlab data types, e.g. % ct=aescrypt(dzip(M),key) % (4) Carefully tested but no warranty, use at your own risk. % (5) Michael Kleder, Nov 2005 % % EXAMPLE: % % M=rand(100); % key='This is my test encryption key, for trial use.'; % ct=aescrypt(dzip(M),key); % N=dunzip(aesdecrypt(ct,key)); % all(M(:)==N(:)) if length(pt) ~= length(pt(:)) error('Plaintext must have only one non-singleton dimension.') end pt=pt(:)'; c = class(pt); if ~strcmp(c,'uint8') & ~strcmp(c,'char') error('Plaintext must be in char or uint8 form.') end pt=uint8(pt); c = class(key); if ~strcmp(c,'uint8') & ~strcmp(c,'char') error('Key be in char or uint8 form.') end x=java.security.MessageDigest.getInstance('MD5'); x.update(uint8(key(:))); key=typecast(x.digest,'uint8'); s=javax.crypto.spec.SecretKeySpec(key,'AES'); c=javax.crypto.Cipher.getInstance('AES'); c.init(1,s) ct = typecast(c.doFinal(pt),'uint8')'; return %%%%%%%%%%% When I put the output in aesdecryption function the error came out such as ??? Error using ==> aesdecrypt at 37 Cyphertext must be in uint8 form. how do i solve this problem. help to me !!!!!!!!!!! urgently ############# function pt = aesdecrypt(ct,key) % AESCRYPT - decrypt a message using 128-bit AES % % USAGE: pt = aescryptpt(ct,key) % % ct = cyphertext, a vector in uint8 form % key = encryption key, which must be a character string or uint8 vector % pt = plaintext, returned in uint8 form % % Notes: (1) This function requires Java, which contains the decryption % routines. % (2) The provided key may have any (nonzero) length. It is hashed % to 128 bits using the MD5 hash algorithm. % (3) You may convert the recovered plaintext to character form % using the CHAR function, e.g., disp(char(pt)). % (4) Use this function with the separate DUNZIP routine to enable % encryption of several Matlab data types, e.g. % M=dunzip(aesdecrypt(ct,key)); % (5) Carefully tested but no warranty, use at your own risk. % (6) Michael Kleder, Nov 2005 % % EXAMPLE: % % M=rand(100); % key='This is my test encryption key, for trial use.'; % ct=aescrypt(dzip(M),key); % N=dunzip(aesdecrypt(ct,key)); % all(M(:)==N(:)) %ct= disp(char('ant')); %key ='this'; if length(ct) ~= length(ct(:)) error('Cyphertext must have only one non-singleton dimension.') end ct=ct(:)'; c = class(ct); if ~strcmp(c,'uint64') error('Cyphertext must be in uint8 form.') end c = class(key); if ~strcmp(c,'uint8') & ~strcmp(c,'char') error('Key be in char or uint64 form.') end x=java.security.MessageDigest.getInstance('MD5'); x.update(uint8(key(:))); key=typecast(x.digest,'uint64'); s=javax.crypto.spec.SecretKeySpec(key,'AES'); c=javax.crypto.Cipher.getInstance('AES'); c.init(2,s) pt = typecast(c.doFinal(ct),'uint8')'; return
|
Pages: 1 Prev: how to check array dimension Next: using workspace data in simulink block |