Debian Codegraph @

freehep-graphicsio-swf/src/main/java/org/freehep/graphicsio/swf/Protect.java

raw symbols SCIP
1 // Copyright 2001, FreeHEP.
2 package org.freehep.graphicsio.swf;
3
4 import java.io.IOException;
5 import java.security.MessageDigest;
6 import java.security.NoSuchAlgorithmException;
7
8 /**
9 * Protect TAG.
10 *
11 * @author Mark Donszelmann
12 * @author Charles Loomis
13 * @version $Id: freehep-graphicsio-swf/src/main/java/org/freehep/graphicsio/swf/Protect.java db861da05344 2005/12/05 00:59:43 duns $
14 */
15 public class Protect extends ControlTag {
16
17 private String password;
18
19 public Protect(String password) {
20 this();
21
22 this.password = password;
23 if (password != null) {
24 try {
25 MessageDigest md5 = MessageDigest.getInstance("MD5");
26 byte[] b = md5.digest(password.getBytes());
27 this.password = new String(b);
28 } catch (NoSuchAlgorithmException nsae) {
29 }
30 }
31 }
32
33 public Protect() {
34 super(24, 2);
35 }
36
37 public SWFTag read(int tagID, SWFInputStream swf, int len)
38 throws IOException {
39
40 if (len != 0) {
41 Protect tag = new Protect();
42 tag.password = new String(swf.readByte(len));
43 return tag;
44 } else {
45 return this;
46 }
47 }
48
49 public void write(int tagID, SWFOutputStream swf) throws IOException {
50 if ((password != null) && (swf.getVersion() >= 5)) {
51 swf.writeByte(password.getBytes());
52 }
53 }
54 }