@@ -52,30 +52,23 @@ function encodeRowID(rowID) {
52
52
}
53
53
}
54
54
55
- // obfuscate value and clear memory for Buffers as they are from Buffer pool
56
- // and are possible to stay longer
55
+ // obfuscate value
57
56
function setObfuscatedValue ( value ) {
58
- const buf = crypto . randomBytes ( Buffer . byteLength ( value ) ) ;
59
- const bytes = Buffer . from ( value , 'utf8' ) ;
60
- const len = Buffer . byteLength ( value ) ;
61
-
62
- const arr = [ ] ;
63
- for ( let i = 0 ; i < len ; i ++ ) {
64
- arr . push ( buf [ i ] ^ bytes [ i ] ) ;
57
+ const valueBytes = Buffer . from ( value ) ;
58
+ const obfuscatedBytes = crypto . randomBytes ( valueBytes . length ) ;
59
+ for ( let i = 0 ; i < valueBytes . length ; i ++ ) {
60
+ valueBytes [ i ] = obfuscatedBytes [ i ] ^ valueBytes [ i ] ;
65
61
}
66
- bytes . fill ( 0 ) ;
67
- return { obfuscatedValue : buf , value : arr } ;
62
+ return { obfuscatedValue : obfuscatedBytes , value : valueBytes } ;
68
63
}
69
64
70
- // returns the Deobfuscated value, after removing the obfuscation
65
+ // returns the deobfuscated value, after removing the obfuscation
71
66
// and clear memory of temporary Buffers coming from Buffer pool
72
- function getDeobfuscatedValue ( value , obfuscatedValue ) {
73
- const arr = [ ] ;
74
- for ( let i = 0 ; i < value . length ; i ++ ) {
75
- arr . push ( value [ i ] ^ obfuscatedValue [ i ] ) ;
67
+ function getDeobfuscatedValue ( valueBytes , obfuscatedBytes ) {
68
+ const buf = Buffer . from ( valueBytes ) ;
69
+ for ( let i = 0 ; i < valueBytes . length ; i ++ ) {
70
+ buf [ i ] = valueBytes [ i ] ^ obfuscatedBytes [ i ] ;
76
71
}
77
- const buf = Buffer . from ( arr ) ;
78
- arr . fill ( 0 ) ;
79
72
const retVal = buf . toString ( ) ;
80
73
buf . fill ( 0 ) ;
81
74
return retVal ;
0 commit comments