PageRenderTime 52ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/FireballFX/Fireball.Ssh/Fireball.Ssh/jsch/KeyPair.cs

http://gluar.googlecode.com/
C# | 756 lines | 624 code | 69 blank | 63 comment | 96 complexity | 1f82f9424c7d1e3ec7878fb10cb698e1 MD5 | raw file
  1. #region Licences
  2. // Copyright (C) 2005 Sebastian Faltoni <sebastian@dotnetfireball.net>
  3. //
  4. // This library is free software; you can redistribute it and/or
  5. // modify it under the terms of the GNU Lesser General Public
  6. // License as published by the Free Software Foundation; either
  7. // version 2.1 of the License, or (at your option) any later version.
  8. //
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. // Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public
  15. // License along with this library; if not, write to the Free Software
  16. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. #endregion Licences
  18. using System;
  19. using System.IO;
  20. using System.Runtime.CompilerServices;
  21. namespace Fireball.Ssh.jsch
  22. {
  23. /* -*-mode:java; c-basic-offset:2; -*- */
  24. /*
  25. Copyright (c) 2002,2003,2004 ymnk, JCraft,Inc. All rights reserved.
  26. Redistribution and use in source and binary forms, with or without
  27. modification, are permitted provided that the following conditions are met:
  28. 1. Redistributions of source code must retain the above copyright notice,
  29. this list of conditions and the following disclaimer.
  30. 2. Redistributions in binary form must reproduce the above copyright
  31. notice, this list of conditions and the following disclaimer in
  32. the documentation and/or other materials provided with the distribution.
  33. 3. The names of the authors may not be used to endorse or promote products
  34. derived from this software without specific prior written permission.
  35. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  36. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  37. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  38. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  39. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  40. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  41. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  42. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  43. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  44. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  45. */
  46. public abstract class KeyPair
  47. {
  48. public const int ERROR=0;
  49. public const int DSA=1;
  50. public const int RSA=2;
  51. public const int UNKNOWN=3;
  52. internal const int VENDOR_OPENSSH=0;
  53. internal const int VENDOR_FSECURE=1;
  54. internal int vendor=VENDOR_OPENSSH;
  55. private static byte[] cr=Util.getBytes("\n");
  56. public static KeyPair genKeyPair(JSch jsch, int type)
  57. {
  58. return genKeyPair(jsch, type, 1024);
  59. }
  60. public static KeyPair genKeyPair(JSch jsch, int type, int key_size)
  61. {
  62. KeyPair kpair=null;
  63. if(type==DSA){ kpair=new KeyPairDSA(jsch); }
  64. else if(type==RSA){ kpair=new KeyPairRSA(jsch); }
  65. if(kpair!=null)
  66. {
  67. kpair.generate(key_size);
  68. }
  69. return kpair;
  70. }
  71. internal abstract void generate(int key_size);
  72. internal abstract byte[] getBegin();
  73. internal abstract byte[] getEnd();
  74. public abstract int getKeySize();
  75. internal JSch jsch=null;
  76. private Cipher cipher;
  77. private HASH hash;
  78. private Random random;
  79. private byte[] passphrase;
  80. public KeyPair(JSch jsch)
  81. {
  82. this.jsch=jsch;
  83. }
  84. static byte[][] header={Util.getBytes( "Proc-Type: 4,ENCRYPTED"),
  85. Util.getBytes("DEK-Info: DES-EDE3-CBC,")};
  86. internal abstract byte[] getPrivateKey();
  87. private void Write(Stream s, byte[] arr)
  88. {
  89. s.Write(arr, 0, arr.Length);
  90. }
  91. public void writePrivateKey(Stream outs)
  92. {
  93. byte[] plain=getPrivateKey();
  94. byte[][] _iv=new byte[1][];
  95. byte[] encoded=encrypt(plain, _iv);
  96. byte[] iv=_iv[0];
  97. byte[] prv=Util.toBase64(encoded, 0, encoded.Length);
  98. try
  99. {
  100. Write(outs, getBegin()); Write(outs,cr);
  101. if(passphrase!=null)
  102. {
  103. Write(outs, header[0]); Write(outs,cr);
  104. Write(outs, header[1]);
  105. for(int j=0; j<iv.Length; j++)
  106. {
  107. outs.WriteByte(b2a((byte)((iv[j]>>4)&0x0f)));
  108. outs.WriteByte(b2a((byte)(iv[j]&0x0f)));
  109. }
  110. Write(outs,cr);
  111. Write(outs,cr);
  112. }
  113. int i=0;
  114. while(i<prv.Length)
  115. {
  116. if(i+64<prv.Length)
  117. {
  118. outs.Write(prv, i, 64);
  119. Write(outs,cr);
  120. i+=64;
  121. continue;
  122. }
  123. outs.Write(prv, i, prv.Length-i);
  124. Write(outs,cr);
  125. break;
  126. }
  127. Write(outs, getEnd()); Write(outs,cr);
  128. //outs.close();
  129. }
  130. catch(Exception e)
  131. {
  132. Console.WriteLine(e);
  133. }
  134. }
  135. private static byte[] space=Util.getBytes(" ");
  136. internal abstract byte[] getKeyTypeName();
  137. public abstract int getKeyType();
  138. public virtual byte[] getPublicKeyBlob(){ return publickeyblob; }
  139. public void writePublicKey(Stream outs, String comment)
  140. {
  141. byte[] pubblob=getPublicKeyBlob();
  142. byte[] pub=Util.toBase64(pubblob, 0, pubblob.Length);
  143. try
  144. {
  145. Write(outs, getKeyTypeName()); Write(outs, space);
  146. outs.Write(pub, 0, pub.Length); Write(outs, space);
  147. Write(outs, Util.getBytes( comment));
  148. Write(outs,cr);
  149. }
  150. catch(Exception e)
  151. {
  152. Console.WriteLine(e);
  153. }
  154. }
  155. public void writePublicKey(String name, String comment)
  156. {
  157. FileStream fos=new FileStream(name,FileMode.OpenOrCreate);
  158. writePublicKey(fos, comment);
  159. fos.Close();
  160. }
  161. public void writeSECSHPublicKey(Stream outs, String comment)
  162. {
  163. byte[] pubblob=getPublicKeyBlob();
  164. byte[] pub=Util.toBase64(pubblob, 0, pubblob.Length);
  165. try
  166. {
  167. Write(outs, Util.getBytes( "---- BEGIN SSH2 PUBLIC KEY ----")); Write(outs, cr);
  168. Write(outs, Util.getBytes("Comment: \""+comment+"\"")); Write(outs,cr);
  169. int index=0;
  170. while(index<pub.Length)
  171. {
  172. int len=70;
  173. if((pub.Length-index)<len)len=pub.Length-index;
  174. outs.Write(pub, index, len); Write(outs, cr);
  175. index+=len;
  176. }
  177. Write(outs, Util.getBytes("---- END SSH2 PUBLIC KEY ----")); Write(outs,cr);
  178. }
  179. catch(Exception e)
  180. {
  181. Console.WriteLine(e);
  182. }
  183. }
  184. public void writeSECSHPublicKey(String name, String comment)
  185. {
  186. FileStream fos=new FileStream(name, FileMode.OpenOrCreate);
  187. writeSECSHPublicKey(fos, comment);
  188. fos.Close();
  189. }
  190. public void writePrivateKey(String name)
  191. {
  192. FileStream fos=new FileStream(name, FileMode.OpenOrCreate);
  193. writePrivateKey(fos);
  194. fos.Close();
  195. }
  196. public String getFingerPrint()
  197. {
  198. if(hash==null) hash=genHash();
  199. byte[] kblob=getPublicKeyBlob();
  200. if(kblob==null) return null;
  201. return getKeySize()+" "+Util.getFingerPrint(hash, kblob);
  202. }
  203. private byte[] encrypt(byte[] plain, byte[][] _iv)
  204. {
  205. if(passphrase==null) return plain;
  206. if(cipher==null) cipher=genCipher();
  207. byte[] iv=_iv[0]=new byte[cipher.getIVSize()];
  208. if(random==null) random=genRandom();
  209. random.fill(iv, 0, iv.Length);
  210. byte[] key=genKey(passphrase, iv);
  211. byte[] encoded=plain;
  212. int bsize=cipher.getBlockSize();
  213. if(encoded.Length%bsize!=0)
  214. {
  215. byte[] foo=new byte[(encoded.Length/bsize+1)*bsize];
  216. Array.Copy(encoded, 0, foo, 0, encoded.Length);
  217. encoded=foo;
  218. }
  219. try
  220. {
  221. cipher.init(Cipher.ENCRYPT_MODE, key, iv);
  222. cipher.update(encoded, 0, encoded.Length, encoded, 0);
  223. }
  224. catch(Exception e)
  225. {
  226. Console.WriteLine(e);
  227. }
  228. return encoded;
  229. }
  230. internal abstract bool parse(byte[] data);
  231. private byte[] decrypt(byte[] data, byte[] passphrase, byte[] iv)
  232. {
  233. /*
  234. if(iv==null){ // FSecure
  235. iv=new byte[8];
  236. for(int i=0; i<iv.Length; i++)iv[i]=0;
  237. }
  238. */
  239. try
  240. {
  241. byte[] key=genKey(passphrase, iv);
  242. cipher.init(Cipher.DECRYPT_MODE, key, iv);
  243. byte[] plain=new byte[data.Length];
  244. cipher.update(data, 0, data.Length, plain, 0);
  245. return plain;
  246. }
  247. catch(Exception e)
  248. {
  249. Console.WriteLine(e);
  250. }
  251. return null;
  252. }
  253. internal int writeSEQUENCE(byte[] buf, int index, int len)
  254. {
  255. buf[index++]=0x30;
  256. index=writeLength(buf, index, len);
  257. return index;
  258. }
  259. internal int writeINTEGER(byte[] buf, int index, byte[] data)
  260. {
  261. buf[index++]=0x02;
  262. index=writeLength(buf, index, data.Length);
  263. Array.Copy(data, 0, buf, index, data.Length);
  264. index+=data.Length;
  265. return index;
  266. }
  267. internal int countLength(int len)
  268. {
  269. int i=1;
  270. if(len<=0x7f) return i;
  271. while(len>0)
  272. {
  273. len>>=8;
  274. i++;
  275. }
  276. return i;
  277. }
  278. internal int writeLength(byte[] data, int index, int len)
  279. {
  280. int i=countLength(len)-1;
  281. if(i==0)
  282. {
  283. data[index++]=(byte)len;
  284. return index;
  285. }
  286. data[index++]=(byte)(0x80|i);
  287. int j=index+i;
  288. while(i>0)
  289. {
  290. data[index+i-1]=(byte)(len&0xff);
  291. len>>=8;
  292. i--;
  293. }
  294. return j;
  295. }
  296. private Random genRandom()
  297. {
  298. if(random==null)
  299. {
  300. try
  301. {
  302. Type t=Type.GetType(jsch.getConfig("random"));
  303. random=(Random)Activator.CreateInstance(t);
  304. }
  305. catch(Exception e){ Console.Error.WriteLine("connect: random "+e); }
  306. }
  307. return random;
  308. }
  309. private HASH genHash()
  310. {
  311. try
  312. {
  313. Type t=Type.GetType(jsch.getConfig("md5"));
  314. hash=(HASH)Activator.CreateInstance(t);
  315. hash.init();
  316. }
  317. catch//(Exception e)
  318. {
  319. }
  320. return hash;
  321. }
  322. private Cipher genCipher()
  323. {
  324. try
  325. {
  326. Type t;
  327. t=Type.GetType(jsch.getConfig("3des-cbc"));
  328. cipher=(Cipher)(Activator.CreateInstance(t));
  329. }
  330. catch//(Exception e)
  331. {
  332. }
  333. return cipher;
  334. }
  335. /*
  336. hash is MD5
  337. h(0) <- hash(passphrase, iv);
  338. h(n) <- hash(h(n-1), passphrase, iv);
  339. key <- (h(0),...,h(n))[0,..,key.Length];
  340. */
  341. [MethodImpl(MethodImplOptions.Synchronized)]
  342. internal byte[] genKey(byte[] passphrase, byte[] iv)
  343. {
  344. if(cipher==null) cipher=genCipher();
  345. if(hash==null) hash=genHash();
  346. byte[] key=new byte[cipher.getBlockSize()];
  347. int hsize=hash.getBlockSize();
  348. byte[] hn=new byte[key.Length/hsize*hsize+
  349. (key.Length%hsize==0?0:hsize)];
  350. try
  351. {
  352. byte[] tmp=null;
  353. if(vendor==VENDOR_OPENSSH)
  354. {
  355. for(int index=0; index+hsize<=hn.Length;)
  356. {
  357. if(tmp!=null){ hash.update(tmp, 0, tmp.Length); }
  358. hash.update(passphrase, 0, passphrase.Length);
  359. hash.update(iv, 0, iv.Length);
  360. tmp=hash.digest();
  361. Array.Copy(tmp, 0, hn, index, tmp.Length);
  362. index+=tmp.Length;
  363. }
  364. Array.Copy(hn, 0, key, 0, key.Length);
  365. }
  366. else if(vendor==VENDOR_FSECURE)
  367. {
  368. for(int index=0; index+hsize<=hn.Length;)
  369. {
  370. if(tmp!=null){ hash.update(tmp, 0, tmp.Length); }
  371. hash.update(passphrase, 0, passphrase.Length);
  372. tmp=hash.digest();
  373. Array.Copy(tmp, 0, hn, index, tmp.Length);
  374. index+=tmp.Length;
  375. }
  376. Array.Copy(hn, 0, key, 0, key.Length);
  377. }
  378. }
  379. catch(Exception e)
  380. {
  381. Console.WriteLine(e);
  382. }
  383. return key;
  384. }
  385. public void setPassphrase(String passphrase)
  386. {
  387. if(passphrase==null || passphrase.Length==0)
  388. {
  389. setPassphrase((byte[])null);
  390. }
  391. else
  392. {
  393. setPassphrase(Util.getBytes( passphrase ));
  394. }
  395. }
  396. public void setPassphrase(byte[] passphrase)
  397. {
  398. if(passphrase!=null && passphrase.Length==0)
  399. passphrase=null;
  400. this.passphrase=passphrase;
  401. }
  402. private bool encrypted=false;
  403. private byte[] data=null;
  404. private byte[] iv=null;
  405. private byte[] publickeyblob=null;
  406. public bool isEncrypted(){ return encrypted; }
  407. public bool decrypt(String _passphrase)
  408. {
  409. byte[] passphrase= Util.getBytes( _passphrase );
  410. byte[] foo=decrypt(data, passphrase, iv);
  411. if(parse(foo))
  412. {
  413. encrypted=false;
  414. }
  415. return !encrypted;
  416. }
  417. public static KeyPair load(JSch jsch, String prvkey)
  418. {
  419. String pubkey=prvkey+".pub";
  420. // if(!new File(pubkey).exists())
  421. if(!File.Exists(pubkey))
  422. {
  423. pubkey=null;
  424. }
  425. return load(jsch, prvkey, pubkey);
  426. }
  427. public static KeyPair load(JSch jsch, String prvkey, String pubkey)
  428. {
  429. byte[] iv=new byte[8]; // 8
  430. bool encrypted=true;
  431. byte[] data=null;
  432. byte[] publickeyblob=null;
  433. int type=ERROR;
  434. int vendor=VENDOR_OPENSSH;
  435. try
  436. {
  437. //File file=new File(prvkey);
  438. FileStream fis=File.OpenRead(prvkey);
  439. byte[] buf=new byte[(int)(fis.Length)];
  440. int len=fis.Read(buf, 0, buf.Length);
  441. fis.Close();
  442. int i=0;
  443. while(i<len)
  444. {
  445. if(buf[i]=='B'&& buf[i+1]=='E'&& buf[i+2]=='G'&& buf[i+3]=='I')
  446. {
  447. i+=6;
  448. if(buf[i]=='D'&& buf[i+1]=='S'&& buf[i+2]=='A'){ type=DSA; }
  449. else if(buf[i]=='R'&& buf[i+1]=='S'&& buf[i+2]=='A'){ type=RSA; }
  450. else if(buf[i]=='S'&& buf[i+1]=='S'&& buf[i+2]=='H')
  451. { // FSecure
  452. type=UNKNOWN;
  453. vendor=VENDOR_FSECURE;
  454. }
  455. else
  456. {
  457. //System.outs.println("invalid format: "+identity);
  458. throw new JSchException("invaid privatekey: "+prvkey);
  459. }
  460. i+=3;
  461. continue;
  462. }
  463. if(buf[i]=='C'&& buf[i+1]=='B'&& buf[i+2]=='C'&& buf[i+3]==',')
  464. {
  465. i+=4;
  466. for(int ii=0; ii<iv.Length; ii++)
  467. {
  468. iv[ii]=(byte)(((a2b(buf[i++])<<4)&0xf0)+(a2b(buf[i++])&0xf));
  469. }
  470. continue;
  471. }
  472. if(buf[i]==0x0d &&
  473. i+1<buf.Length && buf[i+1]==0x0a)
  474. {
  475. i++;
  476. continue;
  477. }
  478. if(buf[i]==0x0a && i+1<buf.Length)
  479. {
  480. if(buf[i+1]==0x0a){ i+=2; break; }
  481. if(buf[i+1]==0x0d &&
  482. i+2<buf.Length && buf[i+2]==0x0a)
  483. {
  484. i+=3; break;
  485. }
  486. bool inheader=false;
  487. for(int j=i+1; j<buf.Length; j++)
  488. {
  489. if(buf[j]==0x0a) break;
  490. //if(buf[j]==0x0d) break;
  491. if(buf[j]==':'){inheader=true; break;}
  492. }
  493. if(!inheader)
  494. {
  495. i++;
  496. encrypted=false; // no passphrase
  497. break;
  498. }
  499. }
  500. i++;
  501. }
  502. if(type==ERROR)
  503. {
  504. throw new JSchException("invaid privatekey: "+prvkey);
  505. }
  506. int start=i;
  507. while(i<len)
  508. {
  509. if(buf[i]==0x0a)
  510. {
  511. bool xd=(buf[i-1]==0x0d);
  512. Array.Copy(buf, i+1,
  513. buf,
  514. i-(xd ? 1 : 0),
  515. len-i-1-(xd ? 1 : 0)
  516. );
  517. if(xd)len--;
  518. len--;
  519. continue;
  520. }
  521. if(buf[i]=='-'){ break; }
  522. i++;
  523. }
  524. data=Util.fromBase64(buf, start, i-start);
  525. if(data.Length>4 && // FSecure
  526. data[0]==(byte)0x3f &&
  527. data[1]==(byte)0x6f &&
  528. data[2]==(byte)0xf9 &&
  529. data[3]==(byte)0xeb)
  530. {
  531. Buffer _buf=new Buffer(data);
  532. _buf.getInt(); // 0x3f6ff9be
  533. _buf.getInt();
  534. byte[]_type=_buf.getString();
  535. //System.outs.println("type: "+new String(_type));
  536. byte[] _cipher=_buf.getString();
  537. String cipher=Util.getString(_cipher);
  538. //System.outs.println("cipher: "+cipher);
  539. if(cipher.Equals("3des-cbc"))
  540. {
  541. _buf.getInt();
  542. byte[] foo=new byte[data.Length-_buf.getOffSet()];
  543. _buf.getByte(foo);
  544. data=foo;
  545. encrypted=true;
  546. throw new JSchException("unknown privatekey format: "+prvkey);
  547. }
  548. else if(cipher.Equals("none"))
  549. {
  550. _buf.getInt();
  551. _buf.getInt();
  552. encrypted=false;
  553. byte[] foo=new byte[data.Length-_buf.getOffSet()];
  554. _buf.getByte(foo);
  555. data=foo;
  556. }
  557. }
  558. if(pubkey!=null)
  559. {
  560. try
  561. {
  562. //file=new File(pubkey);
  563. fis=File.OpenRead(pubkey);
  564. buf=new byte[(int)(fis.Length)];
  565. len=fis.Read(buf, 0, buf.Length);
  566. fis.Close();
  567. if(buf.Length>4 && // FSecure's public key
  568. buf[0]=='-' && buf[1]=='-' && buf[2]=='-' && buf[3]=='-')
  569. {
  570. bool valid=true;
  571. i=0;
  572. do{i++;}while(buf.Length>i && buf[i]!=0x0a);
  573. if(buf.Length<=i) {valid=false;}
  574. while(valid)
  575. {
  576. if(buf[i]==0x0a)
  577. {
  578. bool inheader=false;
  579. for(int j=i+1; j<buf.Length; j++)
  580. {
  581. if(buf[j]==0x0a) break;
  582. if(buf[j]==':'){inheader=true; break;}
  583. }
  584. if(!inheader)
  585. {
  586. i++;
  587. break;
  588. }
  589. }
  590. i++;
  591. }
  592. if(buf.Length<=i){valid=false;}
  593. start=i;
  594. while(valid && i<len)
  595. {
  596. if(buf[i]==0x0a)
  597. {
  598. Array.Copy(buf, i+1, buf, i, len-i-1);
  599. len--;
  600. continue;
  601. }
  602. if(buf[i]=='-'){ break; }
  603. i++;
  604. }
  605. if(valid)
  606. {
  607. publickeyblob=Util.fromBase64(buf, start, i-start);
  608. if(type==UNKNOWN)
  609. {
  610. if(publickeyblob[8]=='d'){ type=DSA; }
  611. else if(publickeyblob[8]=='r'){ type=RSA; }
  612. }
  613. }
  614. }
  615. else
  616. {
  617. if(buf[0]=='s'&& buf[1]=='s'&& buf[2]=='h' && buf[3]=='-')
  618. {
  619. i=0;
  620. while(i<len){ if(buf[i]==' ')break; i++;} i++;
  621. if(i<len)
  622. {
  623. start=i;
  624. while(i<len){ if(buf[i]==' ')break; i++;}
  625. publickeyblob=Util.fromBase64(buf, start, i-start);
  626. }
  627. }
  628. }
  629. }
  630. catch//(Exception ee)
  631. {
  632. }
  633. }
  634. }
  635. catch(Exception e)
  636. {
  637. if(e is JSchException) throw (JSchException)e;
  638. throw new JSchException(e.ToString());
  639. }
  640. KeyPair kpair=null;
  641. if(type==DSA){ kpair=new KeyPairDSA(jsch); }
  642. else if(type==RSA){ kpair=new KeyPairRSA(jsch); }
  643. if(kpair!=null)
  644. {
  645. kpair.encrypted=encrypted;
  646. kpair.publickeyblob=publickeyblob;
  647. kpair.vendor=vendor;
  648. if(encrypted)
  649. {
  650. kpair.iv=iv;
  651. kpair.data=data;
  652. }
  653. else
  654. {
  655. if(kpair.parse(data))
  656. {
  657. return kpair;
  658. }
  659. else
  660. {
  661. throw new JSchException("invaid privatekey: "+prvkey);
  662. }
  663. }
  664. }
  665. return kpair;
  666. }
  667. static private byte a2b(byte c)
  668. {
  669. if('0'<=c&&c<='9') return (byte)(c-'0');
  670. return (byte)(c-'a'+10);
  671. }
  672. static private byte b2a(byte c)
  673. {
  674. if(0<=c&&c<=9) return (byte)(c+'0');
  675. return (byte)(c-10+'A');
  676. }
  677. public virtual void dispose()
  678. {
  679. passphrase=null;
  680. }
  681. }
  682. }