Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
New Developer
Posts: 3
Registered: ‎03-03-2014
My Device: 9360 (Developer)
My Carrier: Vodafone

Blackberry 7 encoding issue

[ Edited ]

Hi,

I am having blackberry version 7-9360.I am trying to encode a password by using base64 algorithm..But i am getting wrong encoded string..In blackberry 6 i am getting correct one.so plz help me for blackberry 7 javascript code.

I use 2 js for base64 algorithm

<script src="js/crypto.js"></script>

/*
CryptoJS v3.0.2
code.google.com/p/crypto-js
(c) 2009-2012 by Jeff Mott. All rights reserved.
code.google.com/p/crypto-js/wiki/License
*/
var CryptoJS = CryptoJS || function(i, p) {
    var f = {}, q = f.lib = {}, j = q.Base = function() { function a() { } return { extend: function(h) { a.prototype = this; var d = new a; h && d.mixIn(h); d.$super = this; return d }, create: function() { var a = this.extend(); a.init.apply(a, arguments); return a }, init: function() { }, mixIn: function(a) { for (var d in a) a.hasOwnProperty(d) && (this[d] = a[d]); a.hasOwnProperty("toString") && (this.toString = a.toString) }, clone: function() { return this.$super.extend(this) } } } (), k = q.WordArray = j.extend({ init: function(a, h) {
        a =
this.words = a || []; this.sigBytes = h != p ? h : 4 * a.length
    }, toString: function(a) { return (a || m).stringify(this) }, concat: function(a) { var h = this.words, d = a.words, c = this.sigBytes, a = a.sigBytes; this.clamp(); if (c % 4) for (var b = 0; b < a; b++) h[c + b >>> 2] |= (d[b >>> 2] >>> 24 - 8 * (b % 4) & 255) << 24 - 8 * ((c + b) % 4); else if (65535 < d.length) for (b = 0; b < a; b += 4) h[c + b >>> 2] = d[b >>> 2]; else h.push.apply(h, d); this.sigBytes += a; return this }, clamp: function() { var a = this.words, b = this.sigBytes; a[b >>> 2] &= 4294967295 << 32 - 8 * (b % 4); a.length = i.ceil(b / 4) }, clone: function() {
        var a =
j.clone.call(this); a.words = this.words.slice(0); return a
    }, random: function(a) { for (var b = [], d = 0; d < a; d += 4) b.push(4294967296 * i.random() | 0); return k.create(b, a) } 
    }), r = f.enc = {}, m = r.Hex = { stringify: function(a) { for (var b = a.words, a = a.sigBytes, d = [], c = 0; c < a; c++) { var e = b[c >>> 2] >>> 24 - 8 * (c % 4) & 255; d.push((e >>> 4).toString(16)); d.push((e & 15).toString(16)) } return d.join("") }, parse: function(a) { for (var b = a.length, d = [], c = 0; c < b; c += 2) d[c >>> 3] |= parseInt(a.substr(c, 2), 16) << 24 - 4 * (c % 8); return k.create(d, b / 2) } }, s = r.Latin1 = { stringify: function(a) {
        for (var b =
a.words, a = a.sigBytes, d = [], c = 0; c < a; c++) d.push(String.fromCharCode(b[c >>> 2] >>> 24 - 8 * (c % 4) & 255)); return d.join("")
    }, parse: function(a) { for (var b = a.length, d = [], c = 0; c < b; c++) d[c >>> 2] |= (a.charCodeAt(c) & 255) << 24 - 8 * (c % 4); return k.create(d, b) } 
    }, g = r.Utf8 = { stringify: function(a) { try { return decodeURIComponent(escape(s.stringify(a))) } catch (b) { throw Error("Malformed UTF-8 data"); } }, parse: function(a) { return s.parse(unescape(encodeURIComponent(a))) } }, b = q.BufferedBlockAlgorithm = j.extend({ reset: function() {
        this._data = k.create();
        this._nDataBytes = 0
    }, _append: function(a) { "string" == typeof a && (a = g.parse(a)); this._data.concat(a); this._nDataBytes += a.sigBytes }, _process: function(a) { var b = this._data, d = b.words, c = b.sigBytes, e = this.blockSize, f = c / (4 * e), f = a ? i.ceil(f) : i.max((f | 0) - this._minBufferSize, 0), a = f * e, c = i.min(4 * a, c); if (a) { for (var g = 0; g < a; g += e) this._doProcessBlock(d, g); g = d.splice(0, a); b.sigBytes -= c } return k.create(g, c) }, clone: function() { var a = j.clone.call(this); a._data = this._data.clone(); return a }, _minBufferSize: 0
    }); q.Hasher = b.extend({ init: function() { this.reset() },
        reset: function() { b.reset.call(this); this._doReset() }, update: function(a) { this._append(a); this._process(); return this }, finalize: function(a) { a && this._append(a); this._doFinalize(); return this._hash }, clone: function() { var a = b.clone.call(this); a._hash = this._hash.clone(); return a }, blockSize: 16, _createHelper: function(a) { return function(b, d) { return a.create(d).finalize(b) } }, _createHmacHelper: function(a) { return function(b, d) { return e.HMAC.create(a, d).finalize(b) } } 
    }); var e = f.algo = {}; return f
} (Math);
(function(i) {
    var p = CryptoJS, f = p.lib, q = f.WordArray, f = f.Hasher, j = p.algo, k = [], r = []; (function() { function f(a) { for (var b = i.sqrt(a), d = 2; d <= b; d++) if (!(a % d)) return !1; return !0 } function g(a) { return 4294967296 * (a - (a | 0)) | 0 } for (var b = 2, e = 0; 64 > e; ) f(b) && (8 > e && (k[e] = g(i.pow(b, 0.5))), r[e] = g(i.pow(b, 1 / 3)), e++), b++ })(); var m = [], j = j.SHA256 = f.extend({ _doReset: function() { this._hash = q.create(k.slice(0)) }, _doProcessBlock: function(f, g) {
        for (var b = this._hash.words, e = b[0], a = b[1], h = b[2], d = b[3], c = b[4], i = b[5], j = b[6], k = b[7], l = 0; 64 >
l; l++) { if (16 > l) m[l] = f[g + l] | 0; else { var n = m[l - 15], o = m[l - 2]; m[l] = ((n << 25 | n >>> 7) ^ (n << 14 | n >>> 18) ^ n >>> 3) + m[l - 7] + ((o << 15 | o >>> 17) ^ (o << 13 | o >>> 19) ^ o >>> 10) + m[l - 16] } n = k + ((c << 26 | c >>> 6) ^ (c << 21 | c >>> 11) ^ (c << 7 | c >>> 25)) + (c & i ^ ~c & j) + r[l] + m[l]; o = ((e << 30 | e >>> 2) ^ (e << 19 | e >>> 13) ^ (e << 10 | e >>> 22)) + (e & a ^ e & h ^ a & h); k = j; j = i; i = c; c = d + n | 0; d = h; h = a; a = e; e = n + o | 0 } b[0] = b[0] + e | 0; b[1] = b[1] + a | 0; b[2] = b[2] + h | 0; b[3] = b[3] + d | 0; b[4] = b[4] + c | 0; b[5] = b[5] + i | 0; b[6] = b[6] + j | 0; b[7] = b[7] + k | 0
    }, _doFinalize: function() {
        var f = this._data, g = f.words, b = 8 * this._nDataBytes,
e = 8 * f.sigBytes; g[e >>> 5] |= 128 << 24 - e % 32; g[(e + 64 >>> 9 << 4) + 15] = b; f.sigBytes = 4 * g.length; this._process()
    } 
    }); p.SHA256 = f._createHelper(j); p.HmacSHA256 = f._createHmacHelper(j)
})(Math);

 

<script src="js/base64.js"></script>

/*
CryptoJS v3.0.2
code.google.com/p/crypto-js
(c) 2009-2012 by Jeff Mott. All rights reserved.
code.google.com/p/crypto-js/wiki/License
*/
(function() {
    var h = CryptoJS, i = h.lib.WordArray; h.enc.Base64 = { stringify: function(b) { var e = b.words, f = b.sigBytes, c = this._map; b.clamp(); for (var b = [], a = 0; a < f; a += 3) for (var d = (e[a >>> 2] >>> 24 - 8 * (a % 4) & 255) << 16 | (e[a + 1 >>> 2] >>> 24 - 8 * ((a + 1) % 4) & 255) << 8 | e[a + 2 >>> 2] >>> 24 - 8 * ((a + 2) % 4) & 255, g = 0; 4 > g && a + 0.75 * g < f; g++) b.push(c.charAt(d >>> 6 * (3 - g) & 63)); if (e = c.charAt(64)) for (; b.length % 4; ) b.push(e); return b.join("") }, parse: function(b) {
        var b = b.replace(/\s/g, ""), e = b.length, f = this._map, c = f.charAt(64); c && (c = b.indexOf(c), -1 != c && (e = c));
        for (var c = [], a = 0, d = 0; d < e; d++) if (d % 4) { var g = f.indexOf(b.charAt(d - 1)) << 2 * (d % 4), h = f.indexOf(b.charAt(d)) >>> 6 - 2 * (d % 4); c[a >>> 2] |= (g | h) << 24 - 8 * (a % 4); a++ } return i.create(c, a)
    }, _map: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="}
    })();

 

 var rpass = $('#txtpassword').val();
 var hash = CryptoJS.SHA256(rpass);
 var pass = hash.toString(CryptoJS.enc.Base64);

 

.Thank you.

Developer
Posts: 19,616
Registered: ‎07-14-2008
My Device: Not Specified

Re: Blackberry 7 encoding issue

Welcome to the forums. 

 

I think you are in the wrong forum, this forum is about Java rather than JavaScript.  I will ask for this Thread to be moved to the HTML5/WebWorks forum, which I think is the appropriate home.