@@ -156,6 +156,52 @@ define(function (require, exports, module) {
156156 } ) ;
157157 } ) ;
158158
159+ describe ( "AESEncryptString and AESDecryptString" , function ( ) {
160+ it ( "should encrypt then decrypt roundtrip returning original string" , async function ( ) {
161+ const { key, iv} = TrustRing . generateRandomKeyAndIV ( ) ;
162+ const original = "hello world" ;
163+ const encrypted = await TrustRing . AESEncryptString ( original , key , iv ) ;
164+ const decrypted = await TrustRing . AESDecryptString ( encrypted , key , iv ) ;
165+ expect ( decrypted ) . toBe ( original ) ;
166+ } ) ;
167+
168+ it ( "should produce a hex string output" , async function ( ) {
169+ const { key, iv} = TrustRing . generateRandomKeyAndIV ( ) ;
170+ const encrypted = await TrustRing . AESEncryptString ( "test" , key , iv ) ;
171+ expect ( encrypted ) . toMatch ( / ^ [ a - f 0 - 9 ] + $ / ) ;
172+ } ) ;
173+
174+ it ( "should produce different ciphertext for different plaintext" , async function ( ) {
175+ const { key, iv} = TrustRing . generateRandomKeyAndIV ( ) ;
176+ const enc1 = await TrustRing . AESEncryptString ( "plaintext1" , key , iv ) ;
177+ const enc2 = await TrustRing . AESEncryptString ( "plaintext2" , key , iv ) ;
178+ expect ( enc1 ) . not . toBe ( enc2 ) ;
179+ } ) ;
180+
181+ it ( "should work with empty string" , async function ( ) {
182+ const { key, iv} = TrustRing . generateRandomKeyAndIV ( ) ;
183+ const encrypted = await TrustRing . AESEncryptString ( "" , key , iv ) ;
184+ const decrypted = await TrustRing . AESDecryptString ( encrypted , key , iv ) ;
185+ expect ( decrypted ) . toBe ( "" ) ;
186+ } ) ;
187+
188+ it ( "should work with unicode characters" , async function ( ) {
189+ const { key, iv} = TrustRing . generateRandomKeyAndIV ( ) ;
190+ const original = "测试数据 with émojis 🔒🔑" ;
191+ const encrypted = await TrustRing . AESEncryptString ( original , key , iv ) ;
192+ const decrypted = await TrustRing . AESDecryptString ( encrypted , key , iv ) ;
193+ expect ( decrypted ) . toBe ( original ) ;
194+ } ) ;
195+
196+ it ( "should work with large strings" , async function ( ) {
197+ const { key, iv} = TrustRing . generateRandomKeyAndIV ( ) ;
198+ const original = "x" . repeat ( 10000 ) ;
199+ const encrypted = await TrustRing . AESEncryptString ( original , key , iv ) ;
200+ const decrypted = await TrustRing . AESDecryptString ( encrypted , key , iv ) ;
201+ expect ( decrypted ) . toBe ( original ) ;
202+ } ) ;
203+ } ) ;
204+
159205 describe ( "generateDataSignature and validateDataSignature integration" , function ( ) {
160206 it ( "should work with JSON data like entitlements" , async function ( ) {
161207 const entitlements = {
0 commit comments