Merge 53df0a2e52 into 07eea0f484
				
					
				
			This commit is contained in:
		
						commit
						8cb354b4a4
					
				| @ -27,6 +27,7 @@ const algos = { | |||||||
| } as const; | } as const; | ||||||
| 
 | 
 | ||||||
| type Encoding = keyof typeof enc | 'Bin'; | type Encoding = keyof typeof enc | 'Bin'; | ||||||
|  | type KeyEncoding = 'Text' | 'Hex'; | ||||||
| 
 | 
 | ||||||
| function formatWithEncoding(words: lib.WordArray, encoding: Encoding) { | function formatWithEncoding(words: lib.WordArray, encoding: Encoding) { | ||||||
|   if (encoding === 'Bin') { |   if (encoding === 'Bin') { | ||||||
| @ -39,17 +40,36 @@ const plainText = ref(''); | |||||||
| const secret = ref(''); | const secret = ref(''); | ||||||
| const hashFunction = ref<keyof typeof algos>('SHA256'); | const hashFunction = ref<keyof typeof algos>('SHA256'); | ||||||
| const encoding = ref<Encoding>('Hex'); | const encoding = ref<Encoding>('Hex'); | ||||||
| const hmac = computed(() => | const keyEncoding = ref<KeyEncoding>('Text'); | ||||||
|   formatWithEncoding(algos[hashFunction.value](plainText.value, secret.value), encoding.value), | const hmac = computed(() => { | ||||||
| ); |   // normalize secret according to the key encoding | ||||||
|  |   const key = keyEncoding.value === 'Text' ? secret.value : enc.Hex.parse(secret.value); | ||||||
|  |   return formatWithEncoding(algos[hashFunction.value](plainText.value, key), encoding.value); | ||||||
|  | }); | ||||||
| const { copy } = useCopy({ source: hmac }); | const { copy } = useCopy({ source: hmac }); | ||||||
| </script> | </script> | ||||||
| 
 | 
 | ||||||
| <template> | <template> | ||||||
|   <div flex flex-col gap-4> |   <div flex flex-col gap-4> | ||||||
|     <c-input-text v-model:value="plainText" multiline raw-text placeholder="Plain text to compute the hash..." rows="3" autosize autofocus label="Plain text to compute the hash" /> |     <c-input-text v-model:value="plainText" multiline raw-text placeholder="Plain text to compute the hash..." rows="3" autosize autofocus label="Plain text to compute the hash" /> | ||||||
|     <c-input-text v-model:value="secret" raw-text placeholder="Enter the secret key..." label="Secret key" clearable /> |     <div flex gap-2> | ||||||
| 
 |       <c-input-text v-model:value="secret" placeholder="Enter the secret key..." label="Secret key" raw-text clearable flex-1 /> | ||||||
|  |       <c-select | ||||||
|  |         v-model:value="keyEncoding" label="Key encoding" | ||||||
|  |         flex-1 | ||||||
|  |         placeholder="Select the key encoding..." | ||||||
|  |         :options="[ | ||||||
|  |           { | ||||||
|  |             label: 'Plain Text', | ||||||
|  |             value: 'Text', | ||||||
|  |           }, | ||||||
|  |           { | ||||||
|  |             label: 'Hexadecimal Text', | ||||||
|  |             value: 'Hex', | ||||||
|  |           }, | ||||||
|  |         ]" | ||||||
|  |       /> | ||||||
|  |     </div> | ||||||
|     <div flex gap-2> |     <div flex gap-2> | ||||||
|       <c-select |       <c-select | ||||||
|         v-model:value="hashFunction" label="Hashing function" |         v-model:value="hashFunction" label="Hashing function" | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user