From Clomosy Docs
(Created page with "TCLCrypto component is a cryptographic library used in Clomosy for encryption, hashing, and token operations. It supports modern algorithms such as AES, SHA-2, SHA-3, and JWT. This component allows developers to configure keys, IVs, output formats, and advanced options for cryptography tasks. <div class="table-responsive"> {| class="wikitable" style="border: 2px solid #c3d7e0" ! style="background-color: #c3d7e0"| Feature !!style="background-color: #c3d7e0"| Use of...") |
No edit summary |
||
| (3 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
TCLCrypto component is a cryptographic library used | TCLCrypto component is a cryptographic library used for encryption, hashing, and token operations. | ||
It supports modern algorithms such as AES, SHA-2, SHA-3, and JWT. This component allows developers to configure keys, IVs, output formats, and advanced options for cryptography tasks. | It supports modern algorithms such as AES, SHA-2, SHA-3, and JWT. This component allows developers to configure keys, IVs, output formats, and advanced options for cryptography tasks. | ||
| Line 51: | Line 51: | ||
EditInput: TclEdit; | EditInput: TclEdit; | ||
BtnEncrypt: TclProButton; | BtnEncrypt: TclProButton; | ||
BtnDecrypt: TclProButton; | |||
Crypto: TCLCrypto; | Crypto: TCLCrypto; | ||
AES_CBC: string; | AES_CBC: string; | ||
// Encrypt Button click event | |||
void BtnEncryptOnClick | void BtnEncryptOnClick | ||
{ | { | ||
Crypto = TCLCrypto.Create; | Crypto = TCLCrypto.Create; | ||
try | try | ||
with Crypto.AES do | |||
{ | |||
AType = atCBC; | |||
KeyLength = kl128; | |||
IVMode = userdefined; | |||
Crypto.AES. | IV = 'MyCustomIV123456'; | ||
Crypto. | Key = 'MySecretKey12345'; | ||
OutputFormat = base64; | |||
PaddingMode = PKCS7; | |||
Unicode = yesUni; | |||
} | |||
AES_CBC = Crypto.AES.Encrypt(EditInput.Text); | |||
Memo1.Lines.Add('Encrypted (CBC Base64):' +#13#10+ AES_CBC); | |||
finally | |||
Crypto.Free; | |||
} | |||
} | |||
// Decrypt Button click event | |||
void BtnDecryptOnClick | |||
{ | |||
if (AES_CBC == '') | |||
{ | |||
ShowMessage('No encrypted text available.'); | |||
exit; | |||
} | |||
Crypto = TCLCrypto.Create; | |||
try | |||
with Crypto.AES do | |||
{ | |||
AType = atCBC; | |||
KeyLength = kl128; | |||
IVMode = userdefined; | |||
IV = 'MyCustomIV123456'; | |||
Key = 'MySecretKey12345'; | |||
OutputFormat = base64; | |||
PaddingMode = PKCS7; | |||
Unicode = yesUni; | |||
} | |||
Memo1.Lines.Add('Decrypted Text:' +#13#10+ Crypto.AES.DecryptStr(AES_CBC)); | |||
finally | |||
Crypto.Free; | |||
} | } | ||
} | } | ||
{ | { | ||
MyForm = TCLForm.Create(Self); | MyForm = TCLForm.Create(Self); | ||
| Line 108: | Line 142: | ||
BtnEncrypt.SetclProSettings(BtnEncrypt.clProSettings); | BtnEncrypt.SetclProSettings(BtnEncrypt.clProSettings); | ||
// Decrypt Button | |||
BtnDecrypt = MyForm.AddNewProButton(MyForm,'BtnDecrypt','Decrypt'); | |||
BtnDecrypt.Align = AlTop; | |||
BtnDecrypt.Margins.Left = 10; | |||
BtnDecrypt.Margins.Right = 10; | |||
BtnDecrypt.Margins.Top = 5; | |||
BtnDecrypt.clProSettings.IsRound = True; | |||
BtnDecrypt.clProSettings.RoundHeight = 2; | |||
BtnDecrypt.clProSettings.RoundWidth = 2; | |||
BtnDecrypt.SetclProSettings(BtnDecrypt.clProSettings); | |||
// Events | |||
MyForm.AddNewEvent(BtnEncrypt,tbeOnClick,'BtnEncryptOnClick'); | MyForm.AddNewEvent(BtnEncrypt,tbeOnClick,'BtnEncryptOnClick'); | ||
MyForm.AddNewEvent(BtnDecrypt,tbeOnClick,'BtnDecryptOnClick'); | |||
MyForm.Run; | MyForm.Run; | ||
| Line 130: | Line 175: | ||
SHA3Result = Crypto.SHA3Hash.Hash('Hello World'); | SHA3Result = Crypto.SHA3Hash.Hash('Hello World'); | ||
ShowMessage('SHA-3 (tsha): ' + SHA3Result); | ShowMessage('SHA-3 (tsha): ' + SHA3Result); | ||
finally | |||
Crypto.Free; | |||
} | } | ||
} | } | ||
</pre> | </pre> | ||
| Line 150: | Line 194: | ||
JWTToken = Crypto.JWT.CompactToken('super_secret_key', 256); | JWTToken = Crypto.JWT.CompactToken('super_secret_key', 256); | ||
ShowMessage('JWT: ' + JWTToken); | ShowMessage('JWT: ' + JWTToken); | ||
finally | |||
Crypto.Free; | |||
} | } | ||
} | } | ||
</pre> | </pre> | ||
{{#seo:|title=TCLCrypto Using in Clomosy - Clomosy Docs}} | {{#seo:|title=TCLCrypto Using in Clomosy - Clomosy Docs}} | ||
{{#seo:|description=Explore TCLCrypto on Clomosy! Learn how to use AES, SHA-2, SHA-3, and JWT features with advanced cryptography options}} | {{#seo:|description=Explore TCLCrypto on Clomosy! Learn how to use AES, SHA-2, SHA-3, and JWT features with advanced cryptography options}} | ||
Latest revision as of 07:43, 17 October 2025
TCLCrypto component is a cryptographic library used for encryption, hashing, and token operations. It supports modern algorithms such as AES, SHA-2, SHA-3, and JWT. This component allows developers to configure keys, IVs, output formats, and advanced options for cryptography tasks.
| Feature | Use of | Definition |
|---|---|---|
| TCLCrypto | Crypto = TCLCrypto.Create; | Creates a TCLCrypto object to perform encryption, hashing, and JWT operations. |
| AType | Crypto.AES.AType = atCBC; or Crypto.SHA3Hash.AType = txof; | Selects algorithm type or mode.
AES Options: atCBC, atECB, atCFB, atOFB. SHA3 Options: tsha (standard), txof (extendable output). |
| KeyLength | Crypto.AES.KeyLength = kl256; | Sets key length in bits. Common options: 128, 192, 256. |
| IVMode | Crypto.AES.IVMode = userdefined; | Determines IV usage for AES. Options: userdefined, rand, none. |
| IV | Crypto.AES.IV = 'MyCustomIV'; | Sets the initialization vector when IVMode = userdefined. |
| Key | Crypto.AES.Key = 'MySecretKey1234567890'; | Defines encryption key for AES operations. |
| OutputFormat | Crypto.AES.OutputFormat = base64; or Crypto.SHA2Hash.OutputFormat = hexa; or Crypto.SHA3Hash.OutputFormat = raw; | Sets output format for AES and all hashing algorithms.
Options: base64, hexa, raw. |
| PaddingMode | Crypto.AES.PaddingMode = PKCS7; | Determines padding for AES encryption. Options: PKCS7, ISO10126, None. |
| Unicode | Crypto.AES.Unicode = yesUni; | Enables Unicode support for AES encryption/decryption. |
| Encrypt | CipherText = Crypto.AES.Encrypt('Text'); | Encrypts input text using AES settings. |
| DecryptStr | PlainText = Crypto.AES.DecryptStr(CipherText); | Decrypts AES-encrypted text to plain string. |
| HashSizeBits | Crypto.SHA2Hash.HashSizeBits = 512; or Crypto.SHA3Hash.HashSizeBits = 256; | Sets bit length of hash output. Commonly 256 or 512 bits. |
| Version | Crypto.SHA3Hash.Version = 512; | Defines SHA3 algorithm version, depending on selected mode. |
| Hash | HashResult = Crypto.SHA2Hash.Hash('Text'); or Crypto.SHA3Hash.Hash('Text'); | Generates hash of input text using SHA2 or SHA3 algorithms. |
| JWT.SetClaim | Crypto.JWT.SetClaim('role','admin'); | Adds a key-value claim to the JWT payload. |
| JWT.CompactToken | Token = Crypto.JWT.CompactToken('secret_key', 256); | Generates a signed JWT token. Algorithm bit size adjustable (128, 256, 512). |
Example
var
MyForm: TCLForm;
Memo1: TclMemo;
EditInput: TclEdit;
BtnEncrypt: TclProButton;
BtnDecrypt: TclProButton;
Crypto: TCLCrypto;
AES_CBC: string;
// Encrypt Button click event
void BtnEncryptOnClick
{
Crypto = TCLCrypto.Create;
try
with Crypto.AES do
{
AType = atCBC;
KeyLength = kl128;
IVMode = userdefined;
IV = 'MyCustomIV123456';
Key = 'MySecretKey12345';
OutputFormat = base64;
PaddingMode = PKCS7;
Unicode = yesUni;
}
AES_CBC = Crypto.AES.Encrypt(EditInput.Text);
Memo1.Lines.Add('Encrypted (CBC Base64):' +#13#10+ AES_CBC);
finally
Crypto.Free;
}
}
// Decrypt Button click event
void BtnDecryptOnClick
{
if (AES_CBC == '')
{
ShowMessage('No encrypted text available.');
exit;
}
Crypto = TCLCrypto.Create;
try
with Crypto.AES do
{
AType = atCBC;
KeyLength = kl128;
IVMode = userdefined;
IV = 'MyCustomIV123456';
Key = 'MySecretKey12345';
OutputFormat = base64;
PaddingMode = PKCS7;
Unicode = yesUni;
}
Memo1.Lines.Add('Decrypted Text:' +#13#10+ Crypto.AES.DecryptStr(AES_CBC));
finally
Crypto.Free;
}
}
{
MyForm = TCLForm.Create(Self);
// Edit for user to type
EditInput = MyForm.AddNewEdit(MyForm,'EditInput','');
EditInput.Align = alTop;
EditInput.Margins.Left = 10;
EditInput.Margins.Right = 10;
EditInput.Margins.Top = 10;
// Memo for show result
Memo1 = MyForm.AddNewMemo(MyForm,'Memo1','');
Memo1.Align = alClient;
Memo1.Margins.Left = 10;
Memo1.Margins.Right = 10;
Memo1.Margins.Top = 5;
Memo1.Margins.Bottom = 10;
Memo1.ReadOnly = True;
// Encrypt Button
BtnEncrypt = MyForm.AddNewProButton(MyForm,'BtnEncrypt','Encrypt');
BtnEncrypt.Align = AlTop;
BtnEncrypt.Margins.Left = 10;
BtnEncrypt.Margins.Right = 10;
BtnEncrypt.Margins.Top = 5;
BtnEncrypt.clProSettings.IsRound = True;
BtnEncrypt.clProSettings.RoundHeight = 2;
BtnEncrypt.clProSettings.RoundWidth = 2;
BtnEncrypt.SetclProSettings(BtnEncrypt.clProSettings);
// Decrypt Button
BtnDecrypt = MyForm.AddNewProButton(MyForm,'BtnDecrypt','Decrypt');
BtnDecrypt.Align = AlTop;
BtnDecrypt.Margins.Left = 10;
BtnDecrypt.Margins.Right = 10;
BtnDecrypt.Margins.Top = 5;
BtnDecrypt.clProSettings.IsRound = True;
BtnDecrypt.clProSettings.RoundHeight = 2;
BtnDecrypt.clProSettings.RoundWidth = 2;
BtnDecrypt.SetclProSettings(BtnDecrypt.clProSettings);
// Events
MyForm.AddNewEvent(BtnEncrypt,tbeOnClick,'BtnEncryptOnClick');
MyForm.AddNewEvent(BtnDecrypt,tbeOnClick,'BtnDecryptOnClick');
MyForm.Run;
}
Example For SHA3 (tsha mode)
var
Crypto: TCLCrypto;
SHA3Result: string;
{
Crypto = TCLCrypto.Create;
try
Crypto.SHA3Hash.AType = tsha;
Crypto.SHA3Hash.OutputFormat = base64;
Crypto.SHA3Hash.HashSizeBits = 512;
SHA3Result = Crypto.SHA3Hash.Hash('Hello World');
ShowMessage('SHA-3 (tsha): ' + SHA3Result);
finally
Crypto.Free;
}
}
Example For JWT Token
var
Crypto: TCLCrypto;
JWTToken: string;
{
Crypto = TCLCrypto.Create;
try
Crypto.JWT.SetClaim('user', 'reader');
Crypto.JWT.SetClaim('scope', 'reader');
JWTToken = Crypto.JWT.CompactToken('super_secret_key', 256);
ShowMessage('JWT: ' + JWTToken);
finally
Crypto.Free;
}
}