Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
aes algorithm in matlab

Subject: aes algorithm in matlab

From: smith grit

Date: 3 Feb, 2010 08:44:05

Message: 1 of 2

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

Subject: aes algorithm in matlab

From: Jeremy

Date: 18 Mar, 2011 04:38:05

Message: 2 of 2

Hi. Do you still have the functions aescrypt and aesdecrypt that you could send me? For some reason they are no longer available on the FEX.
Thanks- Jeremy

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us